From 3304e1e517fb8aac008c4684e72a4b59b408414a Mon Sep 17 00:00:00 2001 From: Kahrl Date: Tue, 25 Aug 2015 07:44:53 +0200 Subject: 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. --- src/script/lua_api/l_env.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/script/lua_api') diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 28afdd071..4e0164d90 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -52,8 +52,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n, sanity_check(lua_checkstack(L, 20)); StackUnroller stack_unroller(L); - lua_pushcfunction(L, script_error_handler); - int errorhandler = lua_gettop(L); + int error_handler = PUSH_ERROR_HANDLER(L); // Get registered_abms lua_getglobal(L, "core"); @@ -80,7 +79,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n, lua_pushnumber(L, active_object_count); lua_pushnumber(L, active_object_count_wider); - int result = lua_pcall(L, 4, 0, errorhandler); + int result = lua_pcall(L, 4, 0, error_handler); if (result) scriptIface->scriptError(result, "LuaABM::trigger"); @@ -412,8 +411,7 @@ int ModApiEnvMod::l_add_item(lua_State *L) if(item.empty() || !item.isKnown(getServer(L)->idef())) return 0; - lua_pushcfunction(L, script_error_handler); - int errorhandler = lua_gettop(L); + int error_handler = PUSH_ERROR_HANDLER(L); // Use spawn_item to spawn a __builtin:item lua_getglobal(L, "core"); @@ -424,9 +422,9 @@ int ModApiEnvMod::l_add_item(lua_State *L) lua_pushvalue(L, 1); lua_pushstring(L, item.getItemString().c_str()); - PCALL_RESL(L, lua_pcall(L, 2, 1, errorhandler)); + PCALL_RESL(L, lua_pcall(L, 2, 1, error_handler)); - lua_remove(L, errorhandler); // Remove error handler + lua_remove(L, error_handler); return 1; } -- cgit v1.2.3