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

@ -95,6 +95,8 @@ bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node,
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// Push callback function on stack
@ -106,7 +108,8 @@ bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node,
pushnode(L, node, ndef);
objectrefGetOrCreate(L, puncher);
pushPointedThing(pointed);
PCALL_RES(lua_pcall(L, 4, 0, m_errorhandler));
PCALL_RES(lua_pcall(L, 4, 0, error_handler));
lua_pop(L, 1); // Pop error handler
return true;
}
@ -115,6 +118,8 @@ bool ScriptApiNode::node_on_dig(v3s16 p, MapNode node,
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// Push callback function on stack
@ -125,7 +130,8 @@ bool ScriptApiNode::node_on_dig(v3s16 p, MapNode node,
push_v3s16(L, p);
pushnode(L, node, ndef);
objectrefGetOrCreate(L, digger);
PCALL_RES(lua_pcall(L, 3, 0, m_errorhandler));
PCALL_RES(lua_pcall(L, 3, 0, error_handler));
lua_pop(L, 1); // Pop error handler
return true;
}
@ -133,6 +139,8 @@ void ScriptApiNode::node_on_construct(v3s16 p, MapNode node)
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// Push callback function on stack
@ -141,13 +149,16 @@ void ScriptApiNode::node_on_construct(v3s16 p, MapNode node)
// Call function
push_v3s16(L, p);
PCALL_RES(lua_pcall(L, 1, 0, m_errorhandler));
PCALL_RES(lua_pcall(L, 1, 0, error_handler));
lua_pop(L, 1); // Pop error handler
}
void ScriptApiNode::node_on_destruct(v3s16 p, MapNode node)
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// Push callback function on stack
@ -156,13 +167,16 @@ void ScriptApiNode::node_on_destruct(v3s16 p, MapNode node)
// Call function
push_v3s16(L, p);
PCALL_RES(lua_pcall(L, 1, 0, m_errorhandler));
PCALL_RES(lua_pcall(L, 1, 0, error_handler));
lua_pop(L, 1); // Pop error handler
}
void ScriptApiNode::node_after_destruct(v3s16 p, MapNode node)
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// Push callback function on stack
@ -172,13 +186,16 @@ void ScriptApiNode::node_after_destruct(v3s16 p, MapNode node)
// Call function
push_v3s16(L, p);
pushnode(L, node, ndef);
PCALL_RES(lua_pcall(L, 2, 0, m_errorhandler));
PCALL_RES(lua_pcall(L, 2, 0, error_handler));
lua_pop(L, 1); // Pop error handler
}
bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime)
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
INodeDefManager *ndef = getServer()->ndef();
// Push callback function on stack
@ -188,7 +205,8 @@ bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime)
// Call function
push_v3s16(L, p);
lua_pushnumber(L,dtime);
PCALL_RES(lua_pcall(L, 2, 1, m_errorhandler));
PCALL_RES(lua_pcall(L, 2, 1, error_handler));
lua_remove(L, error_handler);
return (bool) lua_isboolean(L, -1) && (bool) lua_toboolean(L, -1) == true;
}
@ -199,6 +217,8 @@ void ScriptApiNode::node_on_receive_fields(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
@ -223,23 +243,30 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p,
lua_settable(L, -3);
}
objectrefGetOrCreate(L, sender); // player
PCALL_RES(lua_pcall(L, 4, 0, m_errorhandler));
PCALL_RES(lua_pcall(L, 4, 0, error_handler));
lua_pop(L, 1); // Pop error handler
}
void ScriptApiNode::node_falling_update(v3s16 p)
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
lua_getglobal(L, "nodeupdate");
push_v3s16(L, p);
PCALL_RES(lua_pcall(L, 1, 0, m_errorhandler));
PCALL_RES(lua_pcall(L, 1, 0, error_handler));
lua_pop(L, 1); // Pop error handler
}
void ScriptApiNode::node_falling_update_single(v3s16 p)
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
lua_getglobal(L, "nodeupdate_single");
push_v3s16(L, p);
PCALL_RES(lua_pcall(L, 1, 0, m_errorhandler));
PCALL_RES(lua_pcall(L, 1, 0, error_handler));
lua_pop(L, 1); // Pop error handler
}