1 | -- Note: luaState is a pointer to the LuaState instance that created this lua state |
---|
2 | |
---|
3 | -- Redirect print to the C++ print function |
---|
4 | original_print = print |
---|
5 | print = function(s) |
---|
6 | luaState:luaPrint(s) |
---|
7 | end |
---|
8 | |
---|
9 | -- Create function to log text like COUT, but always prints a line! |
---|
10 | logMessage = function(level, message) |
---|
11 | luaState:luaLog(level, message) |
---|
12 | end |
---|
13 | cout = logMessage |
---|
14 | |
---|
15 | -- Redirect dofile in order to load with the resource manager |
---|
16 | original_dofile = dofile |
---|
17 | dofile = function(filename) |
---|
18 | luaState:doFile(filename) |
---|
19 | -- Required because the C++ function cannot return whatever might be on the stack |
---|
20 | return LuaStateReturnValue -- C-injected global variable |
---|
21 | end |
---|
22 | doFile = dofile |
---|
23 | |
---|
24 | -- Create includeFile function that preparses the file according |
---|
25 | -- to a function provided to the LuaState constructor (in C++) |
---|
26 | include = function(filename) |
---|
27 | luaState:includeFile(filename) |
---|
28 | -- Required because the C++ function cannot return whatever might be on the stack |
---|
29 | return LuaStateReturnValue -- C-injected global variable |
---|
30 | end |
---|
31 | |
---|
32 | -- Replace require function with almost similar behaviour |
---|
33 | -- The loaded modules are then stored with their names (where name has no .lua extension) |
---|
34 | -- Furthermore the ".lua" extension is appended to the moduleName parameter when looking for the file |
---|
35 | original_require = require |
---|
36 | _REQUIREDNAME = "" |
---|
37 | LuaStateReturnValue = true |
---|
38 | require = function(moduleName) |
---|
39 | if not luaState:fileExists(moduleName .. ".lua") then |
---|
40 | logMessage(2, "Warning: Lua function require() could not find file '" .. moduleName .. ".lua' ") |
---|
41 | return nil |
---|
42 | end |
---|
43 | if not _LOADED then |
---|
44 | _LOADED = {} |
---|
45 | end |
---|
46 | if not _LOADED[moduleName] then |
---|
47 | -- save old value |
---|
48 | local _REQUIREDNAME_OLD = _REQUIREDNAME |
---|
49 | _REQUIREDNAME = moduleName |
---|
50 | luaState:doFile(moduleName .. ".lua") |
---|
51 | _LOADED[moduleName] = LuaStateReturnValue |
---|
52 | -- restore old value |
---|
53 | _REQUIREDNAME = _REQUIREDNAME_OLD |
---|
54 | end |
---|
55 | return _LOADED[moduleName] |
---|
56 | end |
---|
57 | |
---|
58 | -- Convenience function for console commands |
---|
59 | orxonox.execute = function(command) |
---|
60 | orxonox.CommandExecutor:execute(command) |
---|
61 | end |
---|
62 | |
---|
63 | -- Convenience function for config values |
---|
64 | orxonox.getConfig = function(section, entry) |
---|
65 | return orxonox.SettingsConfigFile:getInstance():getConfig(section, entry) |
---|
66 | end |
---|
67 | orxonox.config = function(section, entry, value) |
---|
68 | return orxonox.SettingsConfigFile:getInstance():config(section, entry, value) |
---|
69 | end |
---|
70 | orxonox.tconfig = function(section, entry, value) |
---|
71 | return orxonox.SettingsConfigFile:getInstance():tconfig(section, entry, value) |
---|
72 | end |
---|
73 | |
---|
74 | -- Include command line debugger for lua 5.1 |
---|
75 | if _VERSION ~= "Lua 5.0" then |
---|
76 | require("Debugger") |
---|
77 | end |
---|