[Orxonox-commit 1912] r6629 - in code/branches/gamestate: data/lua src/libraries/core

rgrieder at orxonox.net rgrieder at orxonox.net
Sun Mar 28 22:46:07 CEST 2010


Author: rgrieder
Date: 2010-03-28 22:46:07 +0200 (Sun, 28 Mar 2010)
New Revision: 6629

Modified:
   code/branches/gamestate/data/lua/LuaStateInit.lua
   code/branches/gamestate/src/libraries/core/LuaState.cc
Log:
Fixed LuaState::doFile return value issue.

Modified: code/branches/gamestate/data/lua/LuaStateInit.lua
===================================================================
--- code/branches/gamestate/data/lua/LuaStateInit.lua	2010-03-28 18:54:46 UTC (rev 6628)
+++ code/branches/gamestate/data/lua/LuaStateInit.lua	2010-03-28 20:46:07 UTC (rev 6629)
@@ -33,6 +33,8 @@
 -- The loaded modules are then stored with their names (where name has no .lua extension)
 -- Furthermore the ".lua" extension is appended to the moduleName parameter when looking for the file
 original_require = require
+_REQUIREDNAME = ""
+LuaStateReturnValue = true
 require = function(moduleName)
   if not luaState:fileExists(moduleName .. ".lua") then
     logMessage(2, "Warning: Lua function require() could not find file '" .. moduleName .. ".lua' ")
@@ -43,10 +45,10 @@
   end
   if not _LOADED[moduleName] then
     -- save old value
-    _REQUIREDNAME_OLD = _REQUIREDNAME
+    local _REQUIREDNAME_OLD = _REQUIREDNAME
     _REQUIREDNAME = moduleName
     luaState:doFile(moduleName .. ".lua")
-    _LOADED[moduleName] = LuaStateReturnValue or true
+    _LOADED[moduleName] = LuaStateReturnValue
     -- restore old value
     _REQUIREDNAME = _REQUIREDNAME_OLD
   end

Modified: code/branches/gamestate/src/libraries/core/LuaState.cc
===================================================================
--- code/branches/gamestate/src/libraries/core/LuaState.cc	2010-03-28 18:54:46 UTC (rev 6628)
+++ code/branches/gamestate/src/libraries/core/LuaState.cc	2010-03-28 20:46:07 UTC (rev 6629)
@@ -169,10 +169,16 @@
             if (sourceFileInfo != NULL)
                 origin = " originating from " + sourceFileInfo_->filename;
             COUT(1) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl;
-            // return value is nil
-            lua_pushnil(luaState_);
+            // return value is true (not nil!)
+            lua_pushboolean(luaState_, 1);
         }
-        // push return value because it will get lost since the return value of this function is void
+        if (lua_isnil(luaState_, -1))
+        {
+            // Nil return values cause problems
+            lua_pop(luaState_, 1);
+            lua_pushboolean(luaState_, 1);
+        }
+        // Push return value because it will get lost since the return value of this function is void
         lua_setglobal(luaState_, "LuaStateReturnValue");
 
         // Load the old info again




More information about the Orxonox-commit mailing list