[Orxonox-commit 1948] r6665 - code/branches/gamestates2/data/lua

rgrieder at orxonox.net rgrieder at orxonox.net
Wed Mar 31 02:36:48 CEST 2010


Author: rgrieder
Date: 2010-03-31 02:36:48 +0200 (Wed, 31 Mar 2010)
New Revision: 6665

Modified:
   code/branches/gamestates2/data/lua/LuaStateInit.lua
Log:
Fixed problems with the return value of require()

Modified: code/branches/gamestates2/data/lua/LuaStateInit.lua
===================================================================
--- code/branches/gamestates2/data/lua/LuaStateInit.lua	2010-03-30 23:11:21 UTC (rev 6664)
+++ code/branches/gamestates2/data/lua/LuaStateInit.lua	2010-03-31 00:36:48 UTC (rev 6665)
@@ -40,24 +40,30 @@
     logMessage(2, "Warning: Lua function require() could not find file '" .. moduleName .. ".lua' ")
     return nil
   end
+
   if not _LOADED then
     _LOADED = {}
   end
-  if _LOADED[moduleName] == nil then
-    -- save old value
+  if not _LOADED_RETURN_VALUES then
+      _LOADED_RETURN_VALUES = {}
+  end
+
+  if not _LOADED[moduleName] then
+    -- save old value for the required name
     local _REQUIREDNAME_OLD = _REQUIREDNAME
     _REQUIREDNAME = moduleName
+
     luaState:doFile(moduleName .. ".lua")
     -- LuaStateReturnValue is required because if the file returns a table,
     -- it cannot be passed through the C++ function
-    if LuaStateReturnValue == nil then -- C-injected global variable
-        LuaStateReturnValue = true
-    end
-    _LOADED[moduleName] = LuaStateReturnValue -- This entry must never be nil
+    _LOADED_RETURN_VALUES[moduleName] = LuaStateReturnValue
+    _LOADED[moduleName] = true
+
     -- restore old value
     _REQUIREDNAME = _REQUIREDNAME_OLD
   end
-  return _LOADED[moduleName]
+  local asdf = _LOADED_RETURN_VALUES[moduleName]
+  return asdf
 end
 
 




More information about the Orxonox-commit mailing list