Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 31, 2010, 2:36:48 AM (15 years ago)
Author:
rgrieder
Message:

Fixed problems with the return value of require()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestates2/data/lua/LuaStateInit.lua

    r6662 r6665  
    4141    return nil
    4242  end
     43
    4344  if not _LOADED then
    4445    _LOADED = {}
    4546  end
    46   if _LOADED[moduleName] == nil then
    47     -- save old value
     47  if not _LOADED_RETURN_VALUES then
     48      _LOADED_RETURN_VALUES = {}
     49  end
     50
     51  if not _LOADED[moduleName] then
     52    -- save old value for the required name
    4853    local _REQUIREDNAME_OLD = _REQUIREDNAME
    4954    _REQUIREDNAME = moduleName
     55
    5056    luaState:doFile(moduleName .. ".lua")
    5157    -- LuaStateReturnValue is required because if the file returns a table,
    5258    -- it cannot be passed through the C++ function
    53     if LuaStateReturnValue == nil then -- C-injected global variable
    54         LuaStateReturnValue = true
    55     end
    56     _LOADED[moduleName] = LuaStateReturnValue -- This entry must never be nil
     59    _LOADED_RETURN_VALUES[moduleName] = LuaStateReturnValue
     60    _LOADED[moduleName] = true
     61
    5762    -- restore old value
    5863    _REQUIREDNAME = _REQUIREDNAME_OLD
    5964  end
    60   return _LOADED[moduleName]
     65  local asdf = _LOADED_RETURN_VALUES[moduleName]
     66  return asdf
    6167end
    6268
Note: See TracChangeset for help on using the changeset viewer.