Fix ilua not honouring __tostring functions for tables
This gives ilua full access to the debug module so that it can determine whether the table's metatable contains __tostring
This commit is contained in:
parent
12bb52fd4e
commit
d53ac4b496
2 changed files with 21 additions and 13 deletions
|
@ -75,12 +75,19 @@ function ilua.join(tbl,delim,limit,depth)
|
|||
return sub(res,2)
|
||||
end
|
||||
|
||||
-- Need to save this locally because the debug module will be disabled right after this file is loaded
|
||||
-- The or clause is so that it doesn't totally break if someone decides to force-reload ilua during a session.
|
||||
local rawgetmetatable = debug.getmetatable or getmetatable
|
||||
local function getmetatable(t)
|
||||
return rawgetmetatable(t) or {}
|
||||
end
|
||||
|
||||
function ilua.val2str(val)
|
||||
local tp = type(val)
|
||||
if tp == 'function' then
|
||||
return tostring(val)
|
||||
elseif tp == 'table' then
|
||||
if val.__tostring then
|
||||
if getmetatable(val).__tostring then
|
||||
return tostring(val)
|
||||
else
|
||||
return '{'..ilua.join(val,',')..'}'
|
||||
|
|
|
@ -587,18 +587,6 @@ lua_kernel_base::lua_kernel_base()
|
|||
lua_setfield(L, -3, function);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Disable functions from debug which we don't want.
|
||||
lua_getglobal(L, "debug");
|
||||
lua_pushnil(L);
|
||||
while(lua_next(L, -2) != 0) {
|
||||
lua_pop(L, 1);
|
||||
char const* function = lua_tostring(L, -1);
|
||||
if(strcmp(function, "traceback") == 0 || strcmp(function, "getinfo") == 0) continue; //traceback is needed for our error handler
|
||||
lua_pushnil(L); //getinfo is needed for ilua strict mode
|
||||
lua_setfield(L, -3, function);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Delete dofile and loadfile.
|
||||
lua_pushnil(L);
|
||||
|
@ -809,6 +797,19 @@ lua_kernel_base::lua_kernel_base()
|
|||
cmd_log_ << "Error: failed to load ilua.\n";
|
||||
}
|
||||
lua_settop(L, 0);
|
||||
|
||||
// Disable functions from debug which we don't want.
|
||||
// We do this last because ilua needs to be able to use debug.getmetatable
|
||||
lua_getglobal(L, "debug");
|
||||
lua_pushnil(L);
|
||||
while(lua_next(L, -2) != 0) {
|
||||
lua_pop(L, 1);
|
||||
char const* function = lua_tostring(L, -1);
|
||||
if(strcmp(function, "traceback") == 0 || strcmp(function, "getinfo") == 0) continue; //traceback is needed for our error handler
|
||||
lua_pushnil(L); //getinfo is needed for ilua strict mode
|
||||
lua_setfield(L, -3, function);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
lua_kernel_base::~lua_kernel_base()
|
||||
|
|
Loading…
Add table
Reference in a new issue