Il gestore errori può essere sovrascritto. Se chiami Lua da C, per stampare sempre lo stack puoi collegarti alla funzione luaG_errormsg.
in Lua, scrivere:
local _HandlingError = 0
function _ErrorHandler (errobj)
if(_HandlingError == 0) then
_HandlingError = 1
local errStr = tostring(errobj) or ""
if(type(errobj)=='table') then
errStr = "Table: {" .. table.concat(errobj, ',') .. "}"
end
print("Error: \"" .. errStr .. "\"")
--for k,v in pairs(_G) do print("GLOBAL:" , k,v) end
if(type(errobj)=='thread') then
print(debug.traceback(errobj))
else
print(debug.traceback('',2))
end
_HandlingError = 0
end
return false
end
Poi nel ldebug.c, aggiungere luaG_errormsg dopo if (! L-> errfunc = 0)
else
{
lua_getfield(L, LUA_GLOBALSINDEX, "_ErrorHandler");
if (!lua_isfunction(L, -1)) {
lua_pop(L, 1);
}
else {
lua_pushvalue(L, 1);
lua_call(L, 2, 1);
lua_pop(L, 1);
}
}
Grazie, proverò con i tuoi consigli. In relazione a questo, vedo alcuni riferimenti sulle mailing list a "pcall e coroutine non vanno d'accordo". Uso le coroutine, dovrei usare coxpcall e copcall? – proFromDover