xoreos
0.0.5
|
#include <scriptman.h>
Public Member Functions | |
ScriptManager () | |
~ScriptManager () | |
void | init () |
Initialize the script subsystem. More... | |
void | deinit () |
Deinitialize the script subsystem. More... | |
bool | ready () const |
Was the script subsystem successfully initialized? More... | |
void | executeFile (const Common::UString &path) |
Execute a script file. More... | |
void | executeString (const Common::UString &code) |
Execute a script string. More... | |
Variables | callFunction (const Common::UString &name, const Variables ¶ms) |
Call a Lua function. More... | |
Variables | callFunction (const Common::UString &name) |
Variable | getGlobalVariable (const Common::UString &name) const |
TableRef | getGlobalTable (const Common::UString &name) const |
FunctionRef | getGlobalFunction (const Common::UString &name) const |
void | addIgnoredFile (const Common::UString &path) |
Add a file to the ignore list. More... | |
void | removeIgnoredFile (const Common::UString &path) |
Remove a file from the ignore list. More... | |
bool | isIgnoredFile (const Common::UString &path) const |
Is this file in the ignore list? More... | |
void | declareClass (const Common::UString &name) |
Declare a class with the given name. More... | |
void | beginRegister () |
Begin registration of the entities. More... | |
void | endRegister () |
End registration of the entities. More... | |
void | beginRegisterNamespace (const Common::UString &name) |
Begin registration of a namespace. More... | |
void | endRegisterNamespace () |
End registration of the current namespace. More... | |
void | beginRegisterClass (const Common::UString &name, const Common::UString &baseName="", lua_CFunction deleter=0) |
Begin registration of a class. More... | |
void | endRegisterClass () |
End registration of the current class. More... | |
void | registerConstant (const Common::UString &name, float value) |
Register a constant. More... | |
void | registerVariable (const Common::UString &name, lua_CFunction getter, lua_CFunction setter=0) |
Register a variable. More... | |
void | registerFunction (const Common::UString &name, lua_CFunction func) |
Register a function. More... | |
int | getUsedMemoryAmount () const |
Return the amount of memory in use by Lua (in Kbytes). More... | |
void | setLuaInstanceForObject (void *object, const TableRef &luaInstance) |
void | unsetLuaInstanceForObject (void *object) |
const TableRef & | getLuaInstanceForObject (void *object) const |
void | injectNewIndexMetaEventIntoTable (const TableRef &table) |
Private Types | |
typedef std::map< void *, TableRef > | ObjectLuaInstanceMap |
Private Member Functions | |
void | openLuaState () |
Open and setup a new Lua state. More... | |
void | closeLuaState () |
Close the current Lua state. More... | |
void | requireDeclaredClass (const Common::UString &name) const |
Check whether a class with the given name was declared. More... | |
void | registerDefaultBindings () |
void | executeDefaultCode () |
Static Private Member Functions | |
static int | atPanic (lua_State *state) |
Handler of the Lua panic situations. More... | |
static int | luaGetLua (lua_State *state) |
Lua bindings. More... | |
static int | luaPlayFile (lua_State *state) |
static int | luaSetGCInterval (lua_State *state) |
static int | luaRegisterSubst (lua_State *state) |
static int | luaUnregisterSubst (lua_State *state) |
static int | luaRegisterHandler (lua_State *state) |
Private Attributes | |
lua_State * | _luaState |
The Lua state. More... | |
int | _regNestingLevel |
The current nesting level of the registration process. More... | |
std::set< Common::UString > | _ignoredFiles |
A list of files that the script subsystem ignores. More... | |
ObjectLuaInstanceMap | _objectLuaInstances |
Additional Inherited Members | |
Static Public Member Functions inherited from Common::Singleton< ScriptManager > | |
static ScriptManager & | instance () |
static void | destroy () |
Protected Types inherited from Common::Singleton< ScriptManager > | |
typedef ScriptManager | SingletonBaseType |
Protected Member Functions inherited from Common::Singleton< ScriptManager > | |
Singleton () | |
virtual | ~Singleton () |
Lua script manager.
Definition at line 43 of file scriptman.h.
|
private |
Definition at line 116 of file scriptman.h.
Aurora::Lua::ScriptManager::ScriptManager | ( | ) |
Definition at line 49 of file scriptman.cpp.
Aurora::Lua::ScriptManager::~ScriptManager | ( | ) |
Definition at line 53 of file scriptman.cpp.
References deinit().
void Aurora::Lua::ScriptManager::addIgnoredFile | ( | const Common::UString & | path | ) |
Add a file to the ignore list.
Definition at line 161 of file scriptman.cpp.
References _ignoredFiles.
|
staticprivate |
Handler of the Lua panic situations.
Definition at line 373 of file scriptman.cpp.
References error().
Referenced by openLuaState().
void Aurora::Lua::ScriptManager::beginRegister | ( | ) |
Begin registration of the entities.
Definition at line 180 of file scriptman.cpp.
References _luaState, and _regNestingLevel.
Referenced by registerDefaultBindings().
void Aurora::Lua::ScriptManager::beginRegisterClass | ( | const Common::UString & | name, |
const Common::UString & | baseName = "" , |
||
lua_CFunction | deleter = 0 |
||
) |
Begin registration of a class.
Definition at line 215 of file scriptman.cpp.
References _luaState, _regNestingLevel, Common::UString::c_str(), Common::UString::empty(), and requireDeclaredClass().
Referenced by registerDefaultBindings().
void Aurora::Lua::ScriptManager::beginRegisterNamespace | ( | const Common::UString & | name | ) |
Begin registration of a namespace.
Definition at line 197 of file scriptman.cpp.
References _luaState, _regNestingLevel, Common::UString::c_str(), and Common::UString::empty().
Variables Aurora::Lua::ScriptManager::callFunction | ( | const Common::UString & | name, |
const Variables & | params | ||
) |
Call a Lua function.
A "dot" syntax is used to call class methods or table functions. For example, callFunction("module.Class.method", params).
Definition at line 115 of file scriptman.cpp.
References _luaState, _regNestingLevel, Common::UString::c_str(), Aurora::Lua::FunctionRef::call(), Common::UString::empty(), error(), Aurora::Lua::TableRef::getFunctionAt(), getGlobalFunction(), getGlobalTable(), Aurora::Lua::TableRef::getTableAt(), and Common::UString::split().
Referenced by callFunction().
Variables Aurora::Lua::ScriptManager::callFunction | ( | const Common::UString & | name | ) |
Definition at line 140 of file scriptman.cpp.
References callFunction().
|
private |
Close the current Lua state.
Definition at line 315 of file scriptman.cpp.
References _luaState, and _regNestingLevel.
Referenced by deinit().
void Aurora::Lua::ScriptManager::declareClass | ( | const Common::UString & | name | ) |
Declare a class with the given name.
Must be called before the registration of entities.
Definition at line 173 of file scriptman.cpp.
References _luaState, _regNestingLevel, Common::UString::c_str(), and Common::UString::empty().
Referenced by registerDefaultBindings().
void Aurora::Lua::ScriptManager::deinit | ( | ) |
Deinitialize the script subsystem.
Definition at line 68 of file scriptman.cpp.
References _objectLuaInstances, closeLuaState(), and warning().
Referenced by ~ScriptManager().
void Aurora::Lua::ScriptManager::endRegister | ( | ) |
End registration of the entities.
Definition at line 189 of file scriptman.cpp.
References _luaState, and _regNestingLevel.
Referenced by registerDefaultBindings().
void Aurora::Lua::ScriptManager::endRegisterClass | ( | ) |
End registration of the current class.
Definition at line 230 of file scriptman.cpp.
References _luaState, and _regNestingLevel.
Referenced by registerDefaultBindings().
void Aurora::Lua::ScriptManager::endRegisterNamespace | ( | ) |
End registration of the current namespace.
Definition at line 207 of file scriptman.cpp.
References _luaState, and _regNestingLevel.
|
private |
Definition at line 356 of file scriptman.cpp.
References executeString().
Referenced by init().
void Aurora::Lua::ScriptManager::executeFile | ( | const Common::UString & | path | ) |
Execute a script file.
Definition at line 82 of file scriptman.cpp.
References _luaState, _regNestingLevel, Common::UString::c_str(), Common::MemoryReadStream::getData(), isIgnoredFile(), Aurora::kFileTypeLUC, ResMan, Common::MemoryReadStream::size(), and TypeMan.
void Aurora::Lua::ScriptManager::executeString | ( | const Common::UString & | code | ) |
Execute a script string.
Definition at line 106 of file scriptman.cpp.
References _luaState, _regNestingLevel, and Common::UString::c_str().
Referenced by executeDefaultCode().
FunctionRef Aurora::Lua::ScriptManager::getGlobalFunction | ( | const Common::UString & | name | ) | const |
Definition at line 157 of file scriptman.cpp.
References Aurora::Lua::Variable::getFunction(), and getGlobalVariable().
Referenced by callFunction(), and injectNewIndexMetaEventIntoTable().
TableRef Aurora::Lua::ScriptManager::getGlobalTable | ( | const Common::UString & | name | ) | const |
Definition at line 153 of file scriptman.cpp.
References getGlobalVariable(), and Aurora::Lua::Variable::getTable().
Referenced by callFunction().
Variable Aurora::Lua::ScriptManager::getGlobalVariable | ( | const Common::UString & | name | ) | const |
Definition at line 144 of file scriptman.cpp.
References _luaState, and Common::UString::c_str().
Referenced by getGlobalFunction(), and getGlobalTable().
const TableRef & Aurora::Lua::ScriptManager::getLuaInstanceForObject | ( | void * | object | ) | const |
Definition at line 277 of file scriptman.cpp.
References _objectLuaInstances.
int Aurora::Lua::ScriptManager::getUsedMemoryAmount | ( | ) | const |
Return the amount of memory in use by Lua (in Kbytes).
Definition at line 259 of file scriptman.cpp.
References _luaState.
void Aurora::Lua::ScriptManager::init | ( | ) |
Initialize the script subsystem.
Definition at line 60 of file scriptman.cpp.
References executeDefaultCode(), openLuaState(), ready(), and registerDefaultBindings().
void Aurora::Lua::ScriptManager::injectNewIndexMetaEventIntoTable | ( | const TableRef & | table | ) |
Definition at line 290 of file scriptman.cpp.
References getGlobalFunction(), Aurora::Lua::TableRef::getMetaTable(), and Aurora::Lua::TableRef::setFunctionAt().
bool Aurora::Lua::ScriptManager::isIgnoredFile | ( | const Common::UString & | path | ) | const |
Is this file in the ignore list?
Definition at line 169 of file scriptman.cpp.
References _ignoredFiles.
Referenced by executeFile().
|
staticprivate |
Lua bindings.
Definition at line 380 of file scriptman.cpp.
References LuaScriptMan, and Aurora::Lua::Stack::pushUserType().
Referenced by registerDefaultBindings().
|
staticprivate |
Definition at line 388 of file scriptman.cpp.
References Aurora::Lua::Stack::getSize(), Aurora::Lua::Stack::getStringAt(), and LuaScriptMan.
Referenced by registerDefaultBindings().
|
staticprivate |
Definition at line 435 of file scriptman.cpp.
References Aurora::Lua::Stack::getTypeAt(), Aurora::Lua::kTypeString, and Aurora::Lua::kTypeUserType.
Referenced by registerDefaultBindings().
|
staticprivate |
Definition at line 404 of file scriptman.cpp.
References Aurora::Lua::Stack::getRawUserTypeAt(), Aurora::Lua::Stack::getSize(), Aurora::Lua::Stack::getTableAt(), Aurora::Lua::Stack::getUserTypeAt(), Common::Singleton< ScriptManager >::instance(), and LuaScriptMan.
Referenced by registerDefaultBindings().
|
staticprivate |
Definition at line 399 of file scriptman.cpp.
Referenced by registerDefaultBindings().
|
staticprivate |
Definition at line 420 of file scriptman.cpp.
References Aurora::Lua::Stack::getRawUserTypeAt(), Aurora::Lua::Stack::getSize(), Aurora::Lua::Stack::getUserTypeAt(), and LuaScriptMan.
Referenced by registerDefaultBindings().
|
private |
bool Aurora::Lua::ScriptManager::ready | ( | ) | const |
Was the script subsystem successfully initialized?
Definition at line 78 of file scriptman.cpp.
References _luaState.
Referenced by init().
void Aurora::Lua::ScriptManager::registerConstant | ( | const Common::UString & | name, |
float | value | ||
) |
Register a constant.
Definition at line 238 of file scriptman.cpp.
References _luaState, _regNestingLevel, Common::UString::c_str(), and Common::UString::empty().
|
private |
Definition at line 338 of file scriptman.cpp.
References beginRegister(), beginRegisterClass(), declareClass(), endRegister(), endRegisterClass(), luaGetLua(), luaPlayFile(), luaRegisterHandler(), luaRegisterSubst(), luaSetGCInterval(), luaUnregisterSubst(), and registerFunction().
Referenced by init().
void Aurora::Lua::ScriptManager::registerFunction | ( | const Common::UString & | name, |
lua_CFunction | func | ||
) |
Register a function.
Definition at line 252 of file scriptman.cpp.
References _luaState, _regNestingLevel, Common::UString::c_str(), and Common::UString::empty().
Referenced by registerDefaultBindings().
void Aurora::Lua::ScriptManager::registerVariable | ( | const Common::UString & | name, |
lua_CFunction | getter, | ||
lua_CFunction | setter = 0 |
||
) |
Register a variable.
Definition at line 245 of file scriptman.cpp.
References _luaState, _regNestingLevel, Common::UString::c_str(), and Common::UString::empty().
void Aurora::Lua::ScriptManager::removeIgnoredFile | ( | const Common::UString & | path | ) |
Remove a file from the ignore list.
Definition at line 165 of file scriptman.cpp.
References _ignoredFiles.
|
private |
Check whether a class with the given name was declared.
Throw an exception if the check failed.
Definition at line 323 of file scriptman.cpp.
References _luaState, Common::UString::c_str(), and Common::UString::empty().
Referenced by beginRegisterClass().
void Aurora::Lua::ScriptManager::setLuaInstanceForObject | ( | void * | object, |
const TableRef & | luaInstance | ||
) |
Definition at line 263 of file scriptman.cpp.
References _objectLuaInstances.
void Aurora::Lua::ScriptManager::unsetLuaInstanceForObject | ( | void * | object | ) |
Definition at line 271 of file scriptman.cpp.
References _objectLuaInstances.
|
private |
A list of files that the script subsystem ignores.
Definition at line 123 of file scriptman.h.
Referenced by addIgnoredFile(), isIgnoredFile(), and removeIgnoredFile().
|
private |
The Lua state.
Definition at line 119 of file scriptman.h.
Referenced by beginRegister(), beginRegisterClass(), beginRegisterNamespace(), callFunction(), closeLuaState(), declareClass(), endRegister(), endRegisterClass(), endRegisterNamespace(), executeFile(), executeString(), getGlobalVariable(), getUsedMemoryAmount(), openLuaState(), ready(), registerConstant(), registerFunction(), registerVariable(), and requireDeclaredClass().
|
private |
Definition at line 125 of file scriptman.h.
Referenced by deinit(), getLuaInstanceForObject(), setLuaInstanceForObject(), and unsetLuaInstanceForObject().
|
private |
The current nesting level of the registration process.
Definition at line 121 of file scriptman.h.
Referenced by beginRegister(), beginRegisterClass(), beginRegisterNamespace(), callFunction(), closeLuaState(), declareClass(), endRegister(), endRegisterClass(), endRegisterNamespace(), executeFile(), executeString(), registerConstant(), registerFunction(), and registerVariable().