summaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_entity.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/cpp_api/s_entity.cpp')
-rw-r--r--src/script/cpp_api/s_entity.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/script/cpp_api/s_entity.cpp b/src/script/cpp_api/s_entity.cpp
index 0d159846a..378a6bf09 100644
--- a/src/script/cpp_api/s_entity.cpp
+++ b/src/script/cpp_api/s_entity.cpp
@@ -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
}