Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sound4/data/lua/LuaStateInit.lua @ 6629

Last change on this file since 6629 was 6432, checked in by rgrieder, 15 years ago

Changed the way config values associated with general settings (ConfigFileType::Settings) are handled:

  • ConfigFileManager only handles config files listed in the ConfigFileType enum (normal enum again)
  • ConfigFileManager only takes care of ConfigFiles and returns a pointer to the right one, just two functions left. —> use like: ConfigFileManager::getInstance().getConfigFile(myType)→doSomething();
  • Moved all code (except for the argument completion functions) relating to ConfigFileType::Settings to a new class: SettingsConfigFile, which is a Singleton (it doesn't make sense to have multiple instances unless you start coding a lot more)
  • SettingsConfigFile handles config value containers according to their section and entry in the ini file, not according to class and variables names. (In most cases it will be class and variable names though)
  • SettingsConfigFile supports:
    • clear() (removes any file entries not associated to a config value container)
    • updateConfigValues() (does exactly that through the identifier)
    • config, tconfig and getConfig
    • commands listed above are exported to tolua, and tconfig, config and getConfig were given shortcuts in Lua (e.g. orxonox.config)
  • If you need to organise ConfigFiles yourself, just do it without the ConfigFileManager, like the KeyBinder does.
  • All getValue() functions have been split into getOrCreateValue() and getValue(), which is const
  • Removed obsolete config value management code in the Identifier (it still stores and destroys them and provides access to them)

All of that leads to one HUGE advantage:
"config OutputHandler softDebugLevelInGameConsole"
works now :D (any further implications are up to the reader…)
(it didn't work before because the actual config value container is in the InGameConsole singleton)

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1-- Note: luaState is a pointer to the LuaState instance that created this lua state
2
3-- Save original print function in debug
4debug = print
5
6-- Redirect print to the C++ print function
7print = function(s)
8  luaState:luaPrint(s)
9end
10
11-- Create function to log text like COUT, but always prints a line!
12logMessage = function(level, message)
13  luaState:luaLog(level, message)
14end
15
16-- Redirect dofile in order to load with the resource manager
17doFile = 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
21end
22original_dofile = dofile
23dofile = doFile
24
25-- Create includeFile function that preparses the file according
26-- to a function provided to the LuaState constructor (in C++)
27include = function(filename)
28  luaState:includeFile(filename)
29  -- Required because the C++ function cannot return whatever might be on the stack
30  return LuaStateReturnValue -- C-injected global variable
31end
32
33-- Replace require function with almost similar behaviour
34-- The loaded modules are then stored with their names (where name has no .lua extension)
35-- Furthermore the ".lua" extension is appended to the moduleName parameter when looking for the file
36old_require = require
37require = function(moduleName)
38  if not luaState:fileExists(moduleName .. ".lua") then
39    return nil
40  end
41  if not _LOADED then
42    _LOADED = {}
43  end
44  if not _LOADED[moduleName] then
45    -- save old value
46    _REQUIREDNAME_OLD = _REQUIREDNAME
47    _REQUIREDNAME = moduleName
48    luaState:doFile(moduleName .. ".lua")
49    _LOADED[moduleName] = LuaStateReturnValue or true
50    -- restore old value
51    _REQUIREDNAME = _REQUIREDNAME_OLD
52  end
53  return _LOADED[moduleName]
54end
55
56-- Convenience function for console commands
57orxonox.execute = function(command)
58  orxonox.CommandExecutor:execute(command)
59end
60
61-- Convenience function for config values
62orxonox.getConfig = function(section, entry)
63  return orxonox.SettingsConfigFile:getInstance():getConfig(section, entry)
64end
65orxonox.config = function(section, entry, value)
66  return orxonox.SettingsConfigFile:getInstance():config(section, entry, value)
67end
68orxonox.tconfig = function(section, entry, value)
69  return orxonox.SettingsConfigFile:getInstance():tconfig(section, entry, value)
70end
Note: See TracBrowser for help on using the repository browser.