Browse Source

move println implementation to python.Lib

frabbit 11 years ago
parent
commit
0c61f59db9
3 changed files with 11 additions and 16 deletions
  1. 1 1
      std/haxe/Log.hx
  2. 8 11
      std/python/Lib.hx
  3. 2 4
      std/python/_std/Sys.hx

+ 1 - 1
std/haxe/Log.hx

@@ -105,7 +105,7 @@ class Log {
 			} else {
 				str = v;
 			}
-			python.Lib.println([str]);
+			python.Lib.println(str);
 		#end
 	}
 

+ 8 - 11
std/python/Lib.hx

@@ -66,18 +66,15 @@ class Lib
     }
     */
 
-    public static function print(v:Dynamic)
-    {
-       python.lib.Sys.stdout.write(Std.string(v));
-       python.lib.Sys.stdout.flush();
-    }
+  public static function print(v:Dynamic):Void {
+    var str = Std.string(v);
+    untyped __python__('sys.stdout.buffer.write(("%s"%str).encode(\'utf-8\'))');
+  }
 
-    public static function println(v:Array<Dynamic>)
-    {
-       for (e in v) {
-          untyped __python__("print")(Std.string(e));
-       }
-    }
+  public static function println(v:Dynamic):Void {
+    var str = Std.string(v);
+    untyped __python__('sys.stdout.buffer.write(("%s\\n"%str).encode(\'utf-8\'))');
+  }
 
     public static function toPythonIterable <T>(it:Iterable<T>):python.lib.Types.NativeIterable<T>
     {

+ 2 - 4
std/python/_std/Sys.hx

@@ -15,13 +15,11 @@ class Sys {
 	}
 
 	public static function print(v:Dynamic):Void {
-		var str = Std.string(v);
-		untyped __python__('sys.stdout.buffer.write(("%s"%str).encode(\'utf-8\'))');
+		python.Lib.print(v);
 	}
 
 	public static function println(v:Dynamic):Void {
-		var str = Std.string(v);
-		untyped __python__('sys.stdout.buffer.write(("%s\\n"%str).encode(\'utf-8\'))');
+		python.Lib.println(v);
 	}
 
 	public static function args() : Array<String> {