aboutsummaryrefslogtreecommitdiff
path: root/src/lauxlib.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-03 16:11:25 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-03 16:28:01 +1000
commit48b5ebfac37a9d0e4c3622530121e28a50a38a38 (patch)
treeeb0c0af210dbc8d85acfc7b5888dbe7669ec4a81 /src/lauxlib.js
parentebeb17ee158a3b482bd70c8643eacd166d89b4b5 (diff)
downloadfengari-48b5ebfac37a9d0e4c3622530121e28a50a38a38.tar.gz
fengari-48b5ebfac37a9d0e4c3622530121e28a50a38a38.tar.bz2
fengari-48b5ebfac37a9d0e4c3622530121e28a50a38a38.zip
Move .id field from TValue to values themselves
Diffstat (limited to 'src/lauxlib.js')
-rw-r--r--src/lauxlib.js27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index 1921237..9940c77 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -444,7 +444,8 @@ const luaL_tolstring = function(L, idx) {
if (!lua.lua_isstring(L, -1))
luaL_error(L, lua.to_luastring("'__tostring' must return a string", true));
} else {
- switch(lua.lua_type(L, idx)) {
+ let t = lua.lua_type(L, idx);
+ switch(t) {
case lua.LUA_TNUMBER: {
if (lua.lua_isinteger(L, idx))
lua.lua_pushstring(L, lua.to_luastring(lua.lua_tointeger(L, idx).toString()));
@@ -479,7 +480,29 @@ const luaL_tolstring = function(L, idx) {
default:
let tt = luaL_getmetafield(L, idx, lua.to_luastring("__name", true));
let kind = tt === lua.LUA_TSTRING ? lua.lua_tostring(L, -1) : luaL_typename(L, idx);
- lua.lua_pushstring(L, lua.to_luastring(`${lua.to_jsstring(kind)}: 0x${lapi.index2addr(L, -1).id.toString(16)}`));
+ let p = lua.lua_topointer(L, idx);
+ let id;
+ switch (t) {
+ case lua.LUA_TLIGHTUSERDATA:
+ /* user provided object. no id available */
+ id = "<id NYI>";
+ break;
+ case lua.LUA_TFUNCTION:
+ /* light C functions are returned from lua_topointer directly */
+ if (typeof p == "function") {
+ id = "<id NYI>";
+ break;
+ }
+ /* fall through */
+ case lua.LUA_TTABLE:
+ case lua.LUA_TTHREAD:
+ case lua.LUA_TUSERDATA:
+ id = `0x${p.id.toString(16)}`;
+ break;
+ default:
+ throw Error("unhandled type: "+t);
+ }
+ lua.lua_pushstring(L, lua.to_luastring(`${lua.to_jsstring(kind)}: ${id}`));
if (tt !== lua.LUA_TNIL)
lua.lua_remove(L, -2);
break;