1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +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:
Kahrl 2015-08-25 07:44:53 +02:00 committed by est31
parent 8658c8d9b5
commit 3304e1e517
16 changed files with 188 additions and 92 deletions

View file

@ -34,6 +34,8 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove(v3s16 p,
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// If node doesn't exist, we don't know what callback to call
@ -54,12 +56,12 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove(v3s16 p,
lua_pushinteger(L, to_index + 1); // to_index
lua_pushinteger(L, count); // count
objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 7, 1, m_errorhandler));
PCALL_RES(lua_pcall(L, 7, 1, error_handler));
if (!lua_isnumber(L, -1))
throw LuaError("allow_metadata_inventory_move should"
" return a number, guilty node: " + nodename);
int num = luaL_checkinteger(L, -1);
lua_pop(L, 1); // Pop integer
lua_pop(L, 2); // Pop integer and error handler
return num;
}
@ -70,6 +72,8 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut(v3s16 p,
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// If node doesn't exist, we don't know what callback to call
@ -88,12 +92,12 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut(v3s16 p,
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 5, 1, m_errorhandler));
PCALL_RES(lua_pcall(L, 5, 1, error_handler));
if(!lua_isnumber(L, -1))
throw LuaError("allow_metadata_inventory_put should"
" return a number, guilty node: " + nodename);
int num = luaL_checkinteger(L, -1);
lua_pop(L, 1); // Pop integer
lua_pop(L, 2); // Pop integer and error handler
return num;
}
@ -104,6 +108,8 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake(v3s16 p,
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// If node doesn't exist, we don't know what callback to call
@ -122,12 +128,12 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake(v3s16 p,
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 5, 1, m_errorhandler));
PCALL_RES(lua_pcall(L, 5, 1, error_handler));
if (!lua_isnumber(L, -1))
throw LuaError("allow_metadata_inventory_take should"
" return a number, guilty node: " + nodename);
int num = luaL_checkinteger(L, -1);
lua_pop(L, 1); // Pop integer
lua_pop(L, 2); // Pop integer and error handler
return num;
}
@ -139,6 +145,8 @@ void ScriptApiNodemeta::nodemeta_inventory_OnMove(v3s16 p,
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// If node doesn't exist, we don't know what callback to call
@ -159,7 +167,8 @@ void ScriptApiNodemeta::nodemeta_inventory_OnMove(v3s16 p,
lua_pushinteger(L, to_index + 1); // to_index
lua_pushinteger(L, count); // count
objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 7, 0, m_errorhandler));
PCALL_RES(lua_pcall(L, 7, 0, error_handler));
lua_pop(L, 1); // Pop error handler
}
// Report put items
@ -169,6 +178,8 @@ void ScriptApiNodemeta::nodemeta_inventory_OnPut(v3s16 p,
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// If node doesn't exist, we don't know what callback to call
@ -187,7 +198,8 @@ void ScriptApiNodemeta::nodemeta_inventory_OnPut(v3s16 p,
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 5, 0, m_errorhandler));
PCALL_RES(lua_pcall(L, 5, 0, error_handler));
lua_pop(L, 1); // Pop error handler
}
// Report taken items
@ -197,6 +209,8 @@ void ScriptApiNodemeta::nodemeta_inventory_OnTake(v3s16 p,
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// If node doesn't exist, we don't know what callback to call
@ -215,7 +229,8 @@ void ScriptApiNodemeta::nodemeta_inventory_OnTake(v3s16 p,
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 5, 0, m_errorhandler));
PCALL_RES(lua_pcall(L, 5, 0, error_handler));
lua_pop(L, 1); // Pop error handler
}
ScriptApiNodemeta::ScriptApiNodemeta()