|
@@ -153,110 +153,6 @@ class Boot {
|
|
throw "Cannot cast " + Std.string(o) + " to " + Std.string(t);
|
|
throw "Cannot cast " + Std.string(o) + " to " + Std.string(t);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- Helper method to generate a string representation of an enum
|
|
|
|
- **/
|
|
|
|
- static function printEnum(o:Array<Dynamic>, s:String) {
|
|
|
|
- if (o.length == 2) {
|
|
|
|
- return o[0];
|
|
|
|
- } else {
|
|
|
|
- // parameterized enums are arrays
|
|
|
|
- var str = o[0] + "(";
|
|
|
|
- s += "\t";
|
|
|
|
- for (i in 2...o.length) {
|
|
|
|
- if (i != 2)
|
|
|
|
- str += "," + __string_rec(o[i], s);
|
|
|
|
- else
|
|
|
|
- str += __string_rec(o[i], s);
|
|
|
|
- }
|
|
|
|
- return str + ")";
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- Helper method to generate a string representation of a class
|
|
|
|
- **/
|
|
|
|
- static inline function printClass(c:Table<String, Dynamic>, s:String):String {
|
|
|
|
- return '{${printClassRec(c, '', s)}}';
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- Helper method to generate a string representation of a class
|
|
|
|
- **/
|
|
|
|
- static function printClassRec(c:Table<String, Dynamic>, result = '', s:String):String {
|
|
|
|
- var f = Boot.__string_rec;
|
|
|
|
- untyped __lua__("for k,v in pairs(c) do if result ~= '' then result = result .. ', ' end result = result .. k .. ':' .. f(v, s.. '\t') end");
|
|
|
|
- return result;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- Generate a string representation for arbitrary object.
|
|
|
|
- **/
|
|
|
|
- @:ifFeature("has_enum")
|
|
|
|
- static function __string_rec(o:Dynamic, s:String = "") {
|
|
|
|
- if (s.length >= 5)
|
|
|
|
- return "<...>";
|
|
|
|
- return switch (untyped __type__(o)) {
|
|
|
|
- case "nil": "null";
|
|
|
|
- case "number": {
|
|
|
|
- if (o == std.Math.POSITIVE_INFINITY)
|
|
|
|
- "Infinity";
|
|
|
|
- else if (o == std.Math.NEGATIVE_INFINITY)
|
|
|
|
- "-Infinity";
|
|
|
|
- else if (o == 0)
|
|
|
|
- "0";
|
|
|
|
- else if (o != o)
|
|
|
|
- "NaN";
|
|
|
|
- else
|
|
|
|
- untyped tostring(o);
|
|
|
|
- }
|
|
|
|
- case "boolean": untyped tostring(o);
|
|
|
|
- case "string": o;
|
|
|
|
- case "userdata": {
|
|
|
|
- var mt = lua.Lua.getmetatable(o);
|
|
|
|
- if (mt != null && mt.__tostring != null) {
|
|
|
|
- lua.Lua.tostring(o);
|
|
|
|
- } else {
|
|
|
|
- "<userdata>";
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- case "function": "<function>";
|
|
|
|
- case "thread": "<thread>";
|
|
|
|
- case "table": {
|
|
|
|
- if (o.__enum__ != null)
|
|
|
|
- printEnum(o, s);
|
|
|
|
- else if (o.toString != null && !isArray(o))
|
|
|
|
- o.toString();
|
|
|
|
- else if (isArray(o)) {
|
|
|
|
- var o2:Array<Dynamic> = untyped o;
|
|
|
|
- if (s.length > 5)
|
|
|
|
- "[...]"
|
|
|
|
- else
|
|
|
|
- '[${[for (i in o2) __string_rec(i, s + 1)].join(",")}]';
|
|
|
|
- } else if (o.__class__ != null)
|
|
|
|
- printClass(o, s + "\t");
|
|
|
|
- else {
|
|
|
|
- var fields = fieldIterator(o);
|
|
|
|
- var buffer:Table<Int, String> = Table.create();
|
|
|
|
- var first = true;
|
|
|
|
- Table.insert(buffer, "{ ");
|
|
|
|
- for (f in fields) {
|
|
|
|
- if (first)
|
|
|
|
- first = false;
|
|
|
|
- else
|
|
|
|
- Table.insert(buffer, ", ");
|
|
|
|
- Table.insert(buffer, '${Std.string(f)} : ${untyped __string_rec(o[f], s + "\t")}');
|
|
|
|
- }
|
|
|
|
- Table.insert(buffer, " }");
|
|
|
|
- Table.concat(buffer, "");
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- default: {
|
|
|
|
- throw "Unknown Lua type";
|
|
|
|
- null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
Define an array from the given table
|
|
Define an array from the given table
|