From 4dc16cdef46f2d9176c39f7007bc84251b85570c Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 10 Dec 2017 00:34:50 +1100 Subject: src/lobject.js: Add ids in the form of JS constructors for primitives --- src/lobject.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/lobject.js') diff --git a/src/lobject.js b/src/lobject.js index 8754e20..04a08c0 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -576,6 +576,12 @@ 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 (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("")); -- cgit v1.2.3-54-g00ecf From a05c57d01d1ef8d68cebe97e8656c832f9fe4c12 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 10 Dec 2017 00:35:42 +1100 Subject: src/lobject.js: Give functions and objects ids --- src/lobject.js | 9 +++++++++ src/lstate.js | 1 + 2 files changed, 10 insertions(+) (limited to 'src/lobject.js') diff --git a/src/lobject.js b/src/lobject.js index 04a08c0..a5219e5 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -576,6 +576,15 @@ 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 (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 */ 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); -- cgit v1.2.3-54-g00ecf From 085fedefe00d60eee9defa5f59a86361348e2f5c Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 10 Dec 2017 00:43:28 +1100 Subject: src/lobject.js: Add undefined as pointer form of void 0 --- src/lobject.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/lobject.js') diff --git a/src/lobject.js b/src/lobject.js index a5219e5..bc0909d 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -585,6 +585,8 @@ const luaO_pushvfstring = function(L, fmt, argp) { 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 */ -- cgit v1.2.3-54-g00ecf