aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/cpp_api/s_node.cpp')
-rw-r--r--src/script/cpp_api/s_node.cpp45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp
index dac058b13..f90e65642 100644
--- a/src/script/cpp_api/s_node.cpp
+++ b/src/script/cpp_api/s_node.cpp
@@ -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
}