From aa19f4fd042c7085d1b7f6d692ffee7bf5a7ff80 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 09:18:32 +0100 Subject: Improved error resistance in cPluginManager:CallPlugin(). Fixed: If the call failed, all the next plugin calls would fail as well. --- src/Bindings/LuaState.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Bindings') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index d49cd8ef3..6a02197e8 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1066,6 +1066,8 @@ int cLuaState::CallFunctionWithForeignParams( { // Something went wrong, fix the stack and exit lua_pop(m_LuaState, 2); + m_NumCurrentFunctionArgs = -1; + m_CurrentFunctionName.clear(); return -1; } @@ -1081,11 +1083,17 @@ int cLuaState::CallFunctionWithForeignParams( { lua_pop(m_LuaState, CurTop - OldTop); } + + // Reset the internal checking mechanisms: + m_NumCurrentFunctionArgs = -1; + m_CurrentFunctionName.clear(); + return -1; } // Reset the internal checking mechanisms: m_NumCurrentFunctionArgs = -1; + m_CurrentFunctionName.clear(); // Remove the error handler from the stack: lua_remove(m_LuaState, OldTop + 1); -- cgit v1.2.3 From 69c85e5169e5322857d2dfbfccd45281ca1be1c4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 10:29:10 +0100 Subject: Fixed error handling in cPluginManager:CallPlugin() API. Fixed: When the called function malfunctioned, the entire plugin's call was aborted. --- src/Bindings/LuaState.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/Bindings') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 6a02197e8..0a3f6f5b7 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1072,7 +1072,8 @@ int cLuaState::CallFunctionWithForeignParams( } // Call the function, with an error handler: - int s = lua_pcall(m_LuaState, a_SrcParamEnd - a_SrcParamStart + 1, LUA_MULTRET, OldTop); + LogStack("Before pcall"); + int s = lua_pcall(m_LuaState, a_SrcParamEnd - a_SrcParamStart + 1, LUA_MULTRET, OldTop + 1); if (ReportErrors(s)) { LOGWARN("Error while calling function '%s' in '%s'", a_FunctionName.c_str(), m_SubsystemName.c_str()); @@ -1088,7 +1089,9 @@ int cLuaState::CallFunctionWithForeignParams( m_NumCurrentFunctionArgs = -1; m_CurrentFunctionName.clear(); - return -1; + // Make Lua think everything is okay and return 0 values, so that plugins continue executing. + // The failure is indicated by the zero return values. + return 0; } // Reset the internal checking mechanisms: -- cgit v1.2.3 From 1dbfd7eb764f1ad32351257de85925a256c2bc45 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 11:37:34 +0100 Subject: Removed a leftover debug message. --- src/Bindings/LuaState.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/Bindings') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 0a3f6f5b7..1bec5e525 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1072,7 +1072,6 @@ int cLuaState::CallFunctionWithForeignParams( } // Call the function, with an error handler: - LogStack("Before pcall"); int s = lua_pcall(m_LuaState, a_SrcParamEnd - a_SrcParamStart + 1, LUA_MULTRET, OldTop + 1); if (ReportErrors(s)) { -- cgit v1.2.3 From 3dc1452790c1986daa0375da15b79cc3f8ae61a8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 14:26:36 +0100 Subject: Fixed calling plugins with userdata params. --- src/Bindings/LuaState.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Bindings') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 1bec5e525..8dd17c448 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1162,6 +1162,7 @@ int cLuaState::CopyStackFrom(cLuaState & a_SrcLuaState, int a_SrcStart, int a_Sr // Copy the value: void * ud = tolua_touserdata(a_SrcLuaState, i, NULL); tolua_pushusertype(m_LuaState, ud, type); + break; } default: { -- cgit v1.2.3 From 010e64be1124caabeb692f2005db364efb6ac9a0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 22:24:03 +0100 Subject: Removed a useless check in cLuaState. --- src/Bindings/LuaState.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/Bindings') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 8dd17c448..ac5ce47e1 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1018,9 +1018,7 @@ void cLuaState::LogStackTrace(lua_State * a_LuaState) int depth = 0; while (lua_getstack(a_LuaState, depth, &entry)) { - int status = lua_getinfo(a_LuaState, "Sln", &entry); - assert(status); - + lua_getinfo(a_LuaState, "Sln", &entry); LOGWARNING(" %s(%d): %s", entry.short_src, entry.currentline, entry.name ? entry.name : "(no name)"); depth++; } -- cgit v1.2.3 From 82173db9bf9c4f076062ca316c57bf6af9ea1a83 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 4 Feb 2014 22:26:35 +0100 Subject: Fixed a gcc warning in ManualBindings. Constructor member order... --- src/Bindings/ManualBindings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Bindings') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index dbaf32756..9ebdc4b22 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1593,9 +1593,9 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S) int m_NumReturns; cCallback(const AString & a_FunctionName, cLuaState & a_SrcLuaState) : + m_NumReturns(0), m_FunctionName(a_FunctionName), - m_SrcLuaState(a_SrcLuaState), - m_NumReturns(0) + m_SrcLuaState(a_SrcLuaState) { } protected: -- cgit v1.2.3