[Orxonox-commit 1950] r6667 - code/branches/gamestates2/src/libraries/core

rgrieder at orxonox.net rgrieder at orxonox.net
Wed Mar 31 12:46:09 CEST 2010


Author: rgrieder
Date: 2010-03-31 12:46:09 +0200 (Wed, 31 Mar 2010)
New Revision: 6667

Modified:
   code/branches/gamestates2/src/libraries/core/LuaState.cc
Log:
Found the darn bug!
The Lua error handling function may have been referenced with the wrong stack index in case LuaState::doString was called from a Lua function (using the tolua interface).

Modified: code/branches/gamestates2/src/libraries/core/LuaState.cc
===================================================================
--- code/branches/gamestates2/src/libraries/core/LuaState.cc	2010-03-31 00:37:45 UTC (rev 6666)
+++ code/branches/gamestates2/src/libraries/core/LuaState.cc	2010-03-31 10:46:09 UTC (rev 6667)
@@ -176,8 +176,8 @@
         }
 
         // Push custom error handler that uses the debugger
-        int errorHandler = 1;
         lua_getglobal(this->luaState_, "errorHandler");
+        int errorHandler = lua_gettop(luaState_);
         if (lua_isnil(this->luaState_, -1))
         {
             lua_pop(this->luaState_, 1);
@@ -200,7 +200,7 @@
             break;
         case LUA_ERRMEM:    // Memory allocation error
             COUT(1) << "Lua memory allocation error: Consult your dentist immediately!" << std::endl;
-            lua_pop(luaState_, 1);
+            lua_pop(luaState_, 1); // Remove error message
             break;
         }
 
@@ -214,24 +214,24 @@
             case LUA_ERRRUN: // Runtime error
                 // Remove error string from stack (we already display the error in the
                 // 'errorHandler' Lua function in LuaStateInit.lua)
-                lua_pop(luaState_, 1);
                 break;
             case LUA_ERRERR: // Error in the error handler
-                COUT(1) << "Lua error in error handler: " << lua_tostring(luaState_, -1) << std::endl;
+                COUT(1) << "Lua error in error handler. No message available." << std::endl;
                 break;
             case LUA_ERRMEM: // Memory allocation error
                 COUT(1) << "Lua memory allocation error: Consult your dentist immediately!" << std::endl;
-                lua_pop(luaState_, 1);
                 break;
             }
+            if (error != 0)
+                lua_pop(luaState_, 1); // Remove error message
         }
 
         if (error != 0)
-        {
-            // Push a nil return value
-            lua_pushnil(luaState_);
-        }
+            lua_pushnil(luaState_); // Push a nil return value
 
+        if (errorHandler != 0)
+            lua_remove(luaState_, errorHandler); // Remove error handler from stack
+
         // Set return value to a global variable because we cannot return a table in this function
         // here. It would work for numbers, pointers and strings, but certainly not for Lua tables.
         lua_setglobal(luaState_, "LuaStateReturnValue");




More information about the Orxonox-commit mailing list