mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-27 17:28:41 +00:00
Push error handler afresh each time lua_pcall is used
Fixes "double fault" / "error in error handling" messages (issue #1423) and instead shows a complete backtrace.
This commit is contained in:
parent
8658c8d9b5
commit
3304e1e517
16 changed files with 188 additions and 92 deletions
|
@ -80,6 +80,8 @@ void ScriptApiEntity::luaentity_Activate(u16 id,
|
|||
|
||||
verbosestream << "scriptapi_luaentity_activate: id=" << id << std::endl;
|
||||
|
||||
int error_handler = PUSH_ERROR_HANDLER(L);
|
||||
|
||||
// Get core.luaentities[id]
|
||||
luaentity_get(L, id);
|
||||
int object = lua_gettop(L);
|
||||
|
@ -93,11 +95,11 @@ void ScriptApiEntity::luaentity_Activate(u16 id,
|
|||
lua_pushinteger(L, dtime_s);
|
||||
|
||||
setOriginFromTable(object);
|
||||
PCALL_RES(lua_pcall(L, 3, 0, m_errorhandler));
|
||||
PCALL_RES(lua_pcall(L, 3, 0, error_handler));
|
||||
} else {
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1); // Pop object
|
||||
lua_pop(L, 2); // Pop object and error handler
|
||||
}
|
||||
|
||||
void ScriptApiEntity::luaentity_Remove(u16 id)
|
||||
|
@ -126,6 +128,8 @@ std::string ScriptApiEntity::luaentity_GetStaticdata(u16 id)
|
|||
|
||||
//infostream<<"scriptapi_luaentity_get_staticdata: id="<<id<<std::endl;
|
||||
|
||||
int error_handler = PUSH_ERROR_HANDLER(L);
|
||||
|
||||
// Get core.luaentities[id]
|
||||
luaentity_get(L, id);
|
||||
int object = lua_gettop(L);
|
||||
|
@ -140,9 +144,10 @@ std::string ScriptApiEntity::luaentity_GetStaticdata(u16 id)
|
|||
lua_pushvalue(L, object); // self
|
||||
|
||||
setOriginFromTable(object);
|
||||
PCALL_RES(lua_pcall(L, 1, 1, m_errorhandler));
|
||||
PCALL_RES(lua_pcall(L, 1, 1, error_handler));
|
||||
|
||||
lua_remove(L, object); // Remove object
|
||||
lua_remove(L, object);
|
||||
lua_remove(L, error_handler);
|
||||
|
||||
size_t len = 0;
|
||||
const char *s = lua_tolstring(L, -1, &len);
|
||||
|
@ -196,6 +201,8 @@ void ScriptApiEntity::luaentity_Step(u16 id, float dtime)
|
|||
|
||||
//infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl;
|
||||
|
||||
int error_handler = PUSH_ERROR_HANDLER(L);
|
||||
|
||||
// Get core.luaentities[id]
|
||||
luaentity_get(L, id);
|
||||
int object = lua_gettop(L);
|
||||
|
@ -211,9 +218,9 @@ void ScriptApiEntity::luaentity_Step(u16 id, float dtime)
|
|||
lua_pushnumber(L, dtime); // dtime
|
||||
|
||||
setOriginFromTable(object);
|
||||
PCALL_RES(lua_pcall(L, 2, 0, m_errorhandler));
|
||||
PCALL_RES(lua_pcall(L, 2, 0, error_handler));
|
||||
|
||||
lua_pop(L, 1); // Pop object
|
||||
lua_pop(L, 2); // Pop object and error handler
|
||||
}
|
||||
|
||||
// Calls entity:on_punch(ObjectRef puncher, time_from_last_punch,
|
||||
|
@ -226,6 +233,8 @@ void ScriptApiEntity::luaentity_Punch(u16 id,
|
|||
|
||||
//infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl;
|
||||
|
||||
int error_handler = PUSH_ERROR_HANDLER(L);
|
||||
|
||||
// Get core.luaentities[id]
|
||||
luaentity_get(L,id);
|
||||
int object = lua_gettop(L);
|
||||
|
@ -244,9 +253,9 @@ void ScriptApiEntity::luaentity_Punch(u16 id,
|
|||
push_v3f(L, dir);
|
||||
|
||||
setOriginFromTable(object);
|
||||
PCALL_RES(lua_pcall(L, 5, 0, m_errorhandler));
|
||||
PCALL_RES(lua_pcall(L, 5, 0, error_handler));
|
||||
|
||||
lua_pop(L, 1); // Pop object
|
||||
lua_pop(L, 2); // Pop object and error handler
|
||||
}
|
||||
|
||||
// Calls entity:on_rightclick(ObjectRef clicker)
|
||||
|
@ -257,6 +266,8 @@ void ScriptApiEntity::luaentity_Rightclick(u16 id,
|
|||
|
||||
//infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl;
|
||||
|
||||
int error_handler = PUSH_ERROR_HANDLER(L);
|
||||
|
||||
// Get core.luaentities[id]
|
||||
luaentity_get(L, id);
|
||||
int object = lua_gettop(L);
|
||||
|
@ -272,8 +283,8 @@ void ScriptApiEntity::luaentity_Rightclick(u16 id,
|
|||
objectrefGetOrCreate(L, clicker); // Clicker reference
|
||||
|
||||
setOriginFromTable(object);
|
||||
PCALL_RES(lua_pcall(L, 2, 0, m_errorhandler));
|
||||
PCALL_RES(lua_pcall(L, 2, 0, error_handler));
|
||||
|
||||
lua_pop(L, 1); // Pop object
|
||||
lua_pop(L, 2); // Pop object and error handler
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue