summaryrefslogtreecommitdiff
path: root/src/lobject.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-12-10 00:35:42 +1100
committerdaurnimator <quae@daurnimator.com>2017-12-10 00:37:30 +1100
commita05c57d01d1ef8d68cebe97e8656c832f9fe4c12 (patch)
treedb2a6a7f55629497e99504c60302dcfc4d5ea6c2 /src/lobject.js
parent4dc16cdef46f2d9176c39f7007bc84251b85570c (diff)
downloadfengari-a05c57d01d1ef8d68cebe97e8656c832f9fe4c12.tar.gz
fengari-a05c57d01d1ef8d68cebe97e8656c832f9fe4c12.tar.bz2
fengari-a05c57d01d1ef8d68cebe97e8656c832f9fe4c12.zip
src/lobject.js: Give functions and objects ids
Diffstat (limited to 'src/lobject.js')
-rw-r--r--src/lobject.js9
1 files changed, 9 insertions, 0 deletions
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 */