Changeset 5661 for code/branches/resource2/data/lua
- Timestamp:
- Aug 19, 2009, 12:19:11 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource2/data/lua/LuaStateInit.lua
r5654 r5661 1 1 -- Note: luaState is a pointer to the LuaState instance that created this lua state 2 2 3 -- Redirect debug to print3 -- Save original print function in debug 4 4 debug = print 5 5 … … 23 23 resourceGroup = resourceGroup or "NoResourceGroupProvided" 24 24 luaState:doFile(filename, resourceGroup, bSearchOtherPaths) 25 -- Required because the C++ function cannot return whatever might be on the stack 26 return LuaStateReturnValue 25 27 end 28 original_dofile = dofile 26 29 dofile = doFile 27 30 … … 33 36 resourceGroup = resourceGroup or "NoResourceGroupProvided" 34 37 luaState:includeFile(filename, resourceGroup, bSearchOtherPaths) 38 -- Required because the C++ function cannot return whatever might be on the stack 39 return LuaStateReturnValue 35 40 end 41 42 -- Replace require function with almost similar behaviour 43 -- The difference is that you need to provide a resource group 44 -- Default value there is the current one (if present) or else "General" 45 -- But the loaded modules are then stored with only with the name (where name has no .lua extension) 46 -- CAUTION: That also means that you need to take care of conflicting filenames among groups 47 -- Furthermore the moduleName parameters is appended with the .lua extension when looking for the file 48 old_require = require 49 require = function(moduleName, resourceGroup) 50 local bSearchOtherPaths = (resourceGroup == nil) or false 51 resourceGroup = resourceGroup or "NoResourceGroupProvided" 52 if not luaState:fileExists(moduleName .. ".lua", resourceGroup, bSearchOtherPaths) then 53 return nil 54 end 55 if not _LOADED then 56 _LOADED = {} 57 end 58 if not _LOADED[moduleName] then 59 -- save old value 60 _REQUIREDNAME_OLD = _REQUIREDNAME 61 _REQUIREDNAME = moduleName 62 luaState:doFile(moduleName .. ".lua", resourceGroup, bSearchOtherPaths) 63 _LOADED[moduleName] = LuaStateReturnValue or true 64 -- restore old value 65 _REQUIREDNAME = _REQUIREDNAME_OLD 66 end 67 return _LOADED[moduleName] 68 end
Note: See TracChangeset
for help on using the changeset viewer.