diff options
author | Kahrl <kahrl@gmx.net> | 2015-08-25 07:44:53 +0200 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2015-08-27 01:56:06 +0200 |
commit | 3304e1e517fb8aac008c4684e72a4b59b408414a (patch) | |
tree | ddcc820601c02d6783578b7accc68d35a2d312fc /src/script/cpp_api/s_entity.cpp | |
parent | 8658c8d9b5f30dc952eed29a19d619de9210474c (diff) | |
download | minetest-3304e1e517fb8aac008c4684e72a4b59b408414a.tar.gz minetest-3304e1e517fb8aac008c4684e72a4b59b408414a.tar.bz2 minetest-3304e1e517fb8aac008c4684e72a4b59b408414a.zip |
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.
Diffstat (limited to 'src/script/cpp_api/s_entity.cpp')
-rw-r--r-- | src/script/cpp_api/s_entity.cpp | 31 |
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 } |