2
0
Эх сурвалжийг харах

Lua : Better handling of printing arrays and anonymous object types

Justin Donaldson 10 жил өмнө
parent
commit
6c3d3f90d5
1 өөрчлөгдсөн 7 нэмэгдсэн , 3 устгасан
  1. 7 3
      std/lua/Boot.hx

+ 7 - 3
std/lua/Boot.hx

@@ -193,16 +193,20 @@ class Boot {
 			case "function": "<function>";
 			case "thread"  : "<thread>";
 			case "table": {
-				var isArray = untyped Lua.getmetatable(o).__index == Array.prototype;
+				var mt : Dynamic = untyped Lua.getmetatable(o);
+				var isArray = mt != null && mt.__index == untyped Array.prototype;
 				if (s.length > 5) isArray ? "[...]" : "{...}";
+				else if (isArray) '[${[for (i in cast(o,Array<Dynamic>)) __string_rec(i,s+"o")].join(", ")}]'
 				else if (Reflect.hasField(o,"toString")) o.toString();
 				else if (Reflect.hasField(o,"__tostring")) Lua.tostring(o);
 				else if (Reflect.hasField(o,"__enum__")) printEnum(o);
 				else if (Reflect.hasField(o,"__class__")) printClass(o,s);
 				else if (Lua.next(o) == null) "{}";
 				else {
-					throw "Unknown Lua type";
-					null;
+					cast(o, Table<Dynamic,Dynamic>).pairsFold(function(a,b,c){
+						if (c != "{") c+= ", ";
+						return c + __string_rec(a,s + 'o') + ': ' + __string_rec(b, s + 'o');
+					},"{") + "}";
 				}
 			};
 			default : {