Răsfoiți Sursa

added haxe.Log.formatOutput (#6738)

Nicolas Cannasse 8 ani în urmă
părinte
comite
174101dbef

+ 10 - 0
std/cpp/_std/haxe/Log.hx

@@ -36,4 +36,14 @@ package haxe;
 		else
 			nativeTrace(v,infos);
 	}
+
+	public static function formatOutput( v : Dynamic, infos : PosInfos ) : String {
+		var str = Std.string(v);
+		if( infos == null )
+			return str;
+		var pstr = infos.fileName + ":" + infos.lineNumber;
+		if( infos != null && infos.customParams != null ) for( v in infos.customParams ) str += ", " + Std.string(v);
+		return pstr+": "+str;
+	}
+
 }

+ 0 - 38
std/cs/_std/haxe/Log.hx

@@ -1,38 +0,0 @@
-/*
- * Copyright (C)2005-2017 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe;
-
-@:coreApi class Log {
-	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
-		var str:String = null;
-		if (infos != null) {
-			str = infos.fileName + ":" + infos.lineNumber + ": " + v;
-			if (infos.customParams != null)
-			{
-				str += "," + infos.customParams.join(",");
-			}
-		} else {
-			str = v;
-		}
-		cs.system.Console.WriteLine(str);
-	}
-}

+ 13 - 4
std/flash/_std/haxe/Log.hx

@@ -22,12 +22,20 @@
 package haxe;
 
 @:coreApi class Log {
+
+	public static function formatOutput( v : Dynamic, infos : PosInfos ) : String {
+		var str = Std.string(v);
+		if( infos == null )
+			return str;
+		var pstr = infos.fileName + ":" + infos.lineNumber;
+		if( infos != null && infos.customParams != null ) for( v in infos.customParams ) str += ", " + Std.string(v);
+		return pstr+": "+str;
+	}
+
 	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
 		#if (fdb || native_trace)
-			var pstr = infos == null ? "(null)" : infos.fileName + ":" + infos.lineNumber;
-			var str = flash.Boot.__string_rec(v, "");
-			if( infos != null && infos.customParams != null ) for( v in infos.customParams ) str += "," + flash.Boot.__string_rec(v, "");
-			untyped __global__["trace"](pstr+": "+str);
+			var str = formatOutput(v,infos);
+			untyped __global__["trace"](str);
 		#else
 			flash.Boot.__trace(v,infos);
 		#end
@@ -48,4 +56,5 @@ package haxe;
 	public static dynamic function setColor( rgb : Int ) : Void {
 		flash.Boot.__set_trace_color(rgb);
 	}
+
 }

+ 28 - 2
std/haxe/Log.hx

@@ -25,7 +25,19 @@ package haxe;
 	Log primarily provides the `trace()` method, which is invoked upon a call to
 	`trace()` in Haxe code.
 **/
-extern class Log {
+class Log {
+
+	/**
+		Format the output of `trace` before printing it.
+	**/
+	public static function formatOutput( v : Dynamic, infos : PosInfos ) : String {
+		var str = Std.string(v);
+		if( infos == null )
+			return str;
+		var pstr = infos.fileName + ":" + infos.lineNumber;
+		if( infos != null && infos.customParams != null ) for( v in infos.customParams ) str += ", " + Std.string(v);
+		return pstr+": "+str;
+	}
 
 	/**
 		Outputs `v` in a platform-dependent way.
@@ -44,5 +56,19 @@ extern class Log {
 		If it is bound to null, subsequent calls to `trace()` will cause an
 		exception.
 	**/
-	static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void;
+	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
+		var str = formatOutput(v,infos);
+		#if js
+		if( js.Syntax.typeof(untyped console) != "undefined" && (untyped console).log != null )
+			(untyped console).log(str);
+		#elseif lua
+		untyped __define_feature__("use._hx_print",_hx_print(str));
+		#elseif sys
+		Sys.println(str);
+		Sys.stdout().flush();
+		#else
+		throw "Not implemented"
+		#end
+	}
+
 }

+ 0 - 32
std/hl/_std/haxe/Log.hx

@@ -1,32 +0,0 @@
-/*
- * Copyright (C)2005-2017 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe;
-
-@:coreApi class Log {
-	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
-		var pstr = infos == null ? "(null)" : infos.fileName + ":" + infos.lineNumber;
-		var str = Std.string(v);
-		if( infos != null && infos.customParams != null ) for( v in infos.customParams ) str += "," + Std.string(v);
-		Sys.println(pstr+": "+str);
-		Sys.stdout().flush();
-	}
-}

+ 0 - 38
std/java/_std/haxe/Log.hx

@@ -1,38 +0,0 @@
-/*
- * Copyright (C)2005-2017 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe;
-
-@:coreApi class Log {
-	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
-		var str:String = null;
-		if (infos != null) {
-			str = infos.fileName + ":" + infos.lineNumber + ": " + v;
-			if (infos.customParams != null)
-			{
-				str += "," + infos.customParams.join(",");
-			}
-		} else {
-			str = v;
-		}
-		Sys.println(str);
-	}
-}

+ 0 - 35
std/js/_std/haxe/Log.hx

@@ -1,35 +0,0 @@
-/*
- * Copyright (C)2005-2017 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe;
-
-@:coreApi class Log {
-	@:access(js.Boot.__string_rec)
-	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
-		var msg = if (infos != null) infos.fileName + ":" + infos.lineNumber + ": " else "";
-		msg += js.Boot.__string_rec(v, "");
-		if (infos != null && infos.customParams != null)
-			for (v in infos.customParams)
-				msg += "," + js.Boot.__string_rec(v, "");
-		if( js.Syntax.typeof(untyped console) != "undefined" && (untyped console).log != null )
-			(untyped console).log(msg);
-	}
-}

+ 0 - 39
std/lua/_std/haxe/Log.hx

@@ -1,39 +0,0 @@
-/*
- * Copyright (C)2005-2017 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe;
-
-@:coreApi class Log {
-	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
-		var str:String = null;
-		if (infos != null) {
-			str = infos.fileName + ":" + infos.lineNumber + ": " + v;
-			if (infos.customParams != null)
-			{
-				str += "," + infos.customParams.join(",");
-			}
-		} else {
-			str = v;
-		}
-		if (str == null) str = "null";
-		untyped __define_feature__("use._hx_print",_hx_print(str));
-	}
-}

+ 0 - 32
std/neko/_std/haxe/Log.hx

@@ -1,32 +0,0 @@
-/*
- * Copyright (C)2005-2017 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe;
-
-@:coreApi class Log {
-	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
-		untyped {
-			$print(infos.fileName + ":" + infos.lineNumber + ": ", v);
-			if( infos.customParams != null ) for( v in infos.customParams ) $print(",", v);
-			$print("\n");
-		}
-	}
-}

+ 0 - 16
std/php/Boot.hx

@@ -319,22 +319,6 @@ class Boot {
 		throw 'Cannot cast ' + Std.string(value) + ' to ' + getClassName(hxClass.phpClassName);
 	}
 
-	/**
-		`trace()` implementation
-	**/
-	public static function trace( value:Dynamic, infos:PosInfos ) : Void {
-		if (infos != null) {
-			Global.echo('${infos.fileName}:${infos.lineNumber}: ');
-		}
-		Global.echo(stringify(value));
-		if (infos.customParams != null) {
-			for (value in infos.customParams) {
-				Global.echo(',' + stringify(value));
-			}
-		}
-		Global.echo('\n');
-	}
-
 	/**
 		Returns string representation of `value`
 	**/

+ 0 - 28
std/php/_std/haxe/Log.hx

@@ -1,28 +0,0 @@
-/*
- * Copyright (C)2005-2017 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe;
-
-@:coreApi class Log {
-	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
-		php.Boot.trace(v, infos);
-	}
-}

+ 0 - 37
std/python/_std/haxe/Log.hx

@@ -1,37 +0,0 @@
-/*
- * Copyright (C)2005-2017 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe;
-
-@:coreApi class Log {
-	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
-		var str:String = null;
-		if (infos != null) {
-			str = infos.fileName + ":" + Std.string(infos.lineNumber) + ": " + v;
-			if (infos.customParams != null) {
-				str += "," + infos.customParams.join(",");
-			}
-		} else {
-			str = v;
-		}
-		python.Lib.println(str);
-	}
-}