Changeset 6773 for code/branches/gamestates3/data/lua
- Timestamp:
- Apr 23, 2010, 11:41:30 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gamestates3/data/lua/LuaStateInit.lua
r6746 r6773 1 -- Note: luaState is a pointer to the LuaState instance that created this lua state 1 -- LuaStateInit.lua 2 3 -- Note: 'luaState' is a pointer to the LuaState instance that created this lua state 2 4 3 5 -- Redirect print to the C++ print function 4 6 original_print = print 5 print = function(s)7 function print(s) 6 8 luaState:luaPrint(s) 7 9 end 8 10 9 11 -- Create function to log text like COUT, but always prints a line! 10 logMessage = function(level, message)12 function logMessage(level, message) 11 13 luaState:luaLog(level, message) 12 14 end … … 15 17 -- Redirect dofile in order to load with the resource manager 16 18 original_dofile = dofile 17 dofile = function(filename)19 function dofile(filename) 18 20 if not luaState:doFile(filename) then 19 21 error("Error propagation. Do not display") … … 26 28 -- Create includeFile function that preparses the file according 27 29 -- to a function provided to the LuaState constructor (in C++) 28 include = function(filename)30 function include(filename) 29 31 if not luaState:includeFile(filename) then 30 32 error("Error propagation. Do not display") … … 37 39 -- The loaded modules are then stored with their names (where name has no .lua extension) 38 40 -- Furthermore the ".lua" extension is appended to the moduleName parameter when looking for the file 41 _LOADED = {} 42 _LOADED_RETURN_VALUES = {} 43 _REQUIREDNAME = nil 39 44 original_require = require 40 _REQUIREDNAME = "" 41 LuaStateReturnValue = true 42 require = function(moduleName) 45 function require(moduleName) 43 46 if not luaState:fileExists(moduleName .. ".lua") then 44 47 logMessage(2, "Warning: Lua function require() could not find file '" .. moduleName .. ".lua' ") 45 48 return nil 46 end47 48 if not _LOADED then49 _LOADED = {}50 end51 if not _LOADED_RETURN_VALUES then52 _LOADED_RETURN_VALUES = {}53 49 end 54 50 … … 69 65 _REQUIREDNAME = _REQUIREDNAME_OLD 70 66 end 71 local asdf = _LOADED_RETURN_VALUES[moduleName] 72 return asdf 67 return _LOADED_RETURN_VALUES[moduleName] 73 68 end 74 75 69 76 70 -- Load useful tool functions (like handleDefaultArgument) 77 71 require("Tools") 78 79 72 80 73 -- Include command line debugger for lua 5.1 … … 84 77 else 85 78 -- Fallback pause function 86 pause = function()79 function pause() 87 80 logMessage(2, [["Warning: debug() called in Lua, but Debugger is not active. 88 81 Do you have the IOConsole disabled and are you using Lua version 5.1?"]]) … … 91 84 92 85 -- General error handler that gets called whenever an error happens at runtime 93 errorHandler = function(err)86 function errorHandler(err) 94 87 if type(err) == "string" then 95 88 -- Simply return if the error has already been handled … … 112 105 end 113 106 114 115 107 -- Convenience function for console commands 116 108 orxonox.execute = function(command)
Note: See TracChangeset
for help on using the changeset viewer.