diff options
-rw-r--r-- | src/lobject.js | 17 | ||||
-rw-r--r-- | src/lstate.js | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/lobject.js b/src/lobject.js index 97b0514..becec17 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -578,6 +578,23 @@ const luaO_pushvfstring = function(L, fmt, argp) { v instanceof CClosure || v instanceof lfunc.UpVal) { pushstr(L, defs.to_luastring("0x"+v.id.toString(16))); + } else if (v === null) { /* handle null before checking for typeof == object */ + pushstr(L, defs.to_luastring("null")); + } else if (typeof v === "function" || typeof v === "object") { + let id = L.l_G.ids.get(v); + if (!id) { + id = L.l_G.id_counter++; + L.l_G.ids.set(v, id); + } + pushstr(L, defs.to_luastring("0x"+id.toString(16))); + } else if (v === void 0) { + pushstr(L, defs.to_luastring("undefined")); + } else if (typeof v === "number") { /* before check object as null is an object */ + pushstr(L, defs.to_luastring("Number("+v+")")); + } else if (typeof v === "string") { /* before check object as null is an object */ + pushstr(L, defs.to_luastring("String("+JSON.stringify(v)+")")); + } else if (typeof v === "boolean") { /* before check object as null is an object */ + pushstr(L, defs.to_luastring(v?"Boolean(true)":"Boolean(false)")); } else { /* user provided object. no id available */ pushstr(L, defs.to_luastring("<id NYI>")); diff --git a/src/lstate.js b/src/lstate.js index d09bebd..db046dc 100644 --- a/src/lstate.js +++ b/src/lstate.js @@ -74,6 +74,7 @@ class global_State { constructor() { this.id_counter = 0; /* used to give objects unique ids */ + this.ids = new WeakMap(); this.mainthread = null; this.l_registry = new lobject.TValue(CT.LUA_TNIL, null); |