xoreos  0.0.5
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Aurora::Lua::ScriptManager Class Reference

Lua script manager. More...

#include <scriptman.h>

Inheritance diagram for Aurora::Lua::ScriptManager:
Inheritance graph
[legend]
Collaboration diagram for Aurora::Lua::ScriptManager:
Collaboration graph
[legend]

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 &params)
 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 TableRefgetLuaInstanceForObject (void *object) const
 
void injectNewIndexMetaEventIntoTable (const TableRef &table)
 

Private Types

typedef std::map< void *, TableRefObjectLuaInstanceMap
 

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 ()
 

Detailed Description

Lua script manager.

Definition at line 43 of file scriptman.h.

Member Typedef Documentation

◆ ObjectLuaInstanceMap

Definition at line 116 of file scriptman.h.

Constructor & Destructor Documentation

◆ ScriptManager()

Aurora::Lua::ScriptManager::ScriptManager ( )

Definition at line 49 of file scriptman.cpp.

◆ ~ScriptManager()

Aurora::Lua::ScriptManager::~ScriptManager ( )

Definition at line 53 of file scriptman.cpp.

References deinit().

Here is the call graph for this function:

Member Function Documentation

◆ addIgnoredFile()

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.

◆ atPanic()

int Aurora::Lua::ScriptManager::atPanic ( lua_State *  state)
staticprivate

Handler of the Lua panic situations.

Definition at line 373 of file scriptman.cpp.

References error().

Referenced by openLuaState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginRegister()

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().

Here is the caller graph for this function:

◆ beginRegisterClass()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginRegisterNamespace()

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().

Here is the call graph for this function:

◆ callFunction() [1/2]

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ callFunction() [2/2]

Variables Aurora::Lua::ScriptManager::callFunction ( const Common::UString name)

Definition at line 140 of file scriptman.cpp.

References callFunction().

Here is the call graph for this function:

◆ closeLuaState()

void Aurora::Lua::ScriptManager::closeLuaState ( )
private

Close the current Lua state.

Definition at line 315 of file scriptman.cpp.

References _luaState, and _regNestingLevel.

Referenced by deinit().

Here is the caller graph for this function:

◆ declareClass()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deinit()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endRegister()

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().

Here is the caller graph for this function:

◆ endRegisterClass()

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().

Here is the caller graph for this function:

◆ endRegisterNamespace()

void Aurora::Lua::ScriptManager::endRegisterNamespace ( )

End registration of the current namespace.

Definition at line 207 of file scriptman.cpp.

References _luaState, and _regNestingLevel.

◆ executeDefaultCode()

void Aurora::Lua::ScriptManager::executeDefaultCode ( )
private

Definition at line 356 of file scriptman.cpp.

References executeString().

Referenced by init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeFile()

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.

Here is the call graph for this function:

◆ executeString()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGlobalFunction()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGlobalTable()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGlobalVariable()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLuaInstanceForObject()

const TableRef & Aurora::Lua::ScriptManager::getLuaInstanceForObject ( void *  object) const

Definition at line 277 of file scriptman.cpp.

References _objectLuaInstances.

◆ getUsedMemoryAmount()

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.

◆ init()

void Aurora::Lua::ScriptManager::init ( )

Initialize the script subsystem.

Definition at line 60 of file scriptman.cpp.

References executeDefaultCode(), openLuaState(), ready(), and registerDefaultBindings().

Here is the call graph for this function:

◆ injectNewIndexMetaEventIntoTable()

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().

Here is the call graph for this function:

◆ isIgnoredFile()

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().

Here is the caller graph for this function:

◆ luaGetLua()

int Aurora::Lua::ScriptManager::luaGetLua ( lua_State *  state)
staticprivate

Lua bindings.

Definition at line 380 of file scriptman.cpp.

References LuaScriptMan, and Aurora::Lua::Stack::pushUserType().

Referenced by registerDefaultBindings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ luaPlayFile()

int Aurora::Lua::ScriptManager::luaPlayFile ( lua_State *  state)
staticprivate

Definition at line 388 of file scriptman.cpp.

References Aurora::Lua::Stack::getSize(), Aurora::Lua::Stack::getStringAt(), and LuaScriptMan.

Referenced by registerDefaultBindings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ luaRegisterHandler()

int Aurora::Lua::ScriptManager::luaRegisterHandler ( lua_State *  state)
staticprivate

Definition at line 435 of file scriptman.cpp.

References Aurora::Lua::Stack::getTypeAt(), Aurora::Lua::kTypeString, and Aurora::Lua::kTypeUserType.

Referenced by registerDefaultBindings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ luaRegisterSubst()

int Aurora::Lua::ScriptManager::luaRegisterSubst ( lua_State *  state)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ luaSetGCInterval()

int Aurora::Lua::ScriptManager::luaSetGCInterval ( lua_State *  state)
staticprivate

Definition at line 399 of file scriptman.cpp.

Referenced by registerDefaultBindings().

Here is the caller graph for this function:

◆ luaUnregisterSubst()

int Aurora::Lua::ScriptManager::luaUnregisterSubst ( lua_State *  state)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openLuaState()

void Aurora::Lua::ScriptManager::openLuaState ( )
private

Open and setup a new Lua state.

Definition at line 296 of file scriptman.cpp.

References _luaState, and atPanic().

Referenced by init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ready()

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().

Here is the caller graph for this function:

◆ registerConstant()

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().

Here is the call graph for this function:

◆ registerDefaultBindings()

void Aurora::Lua::ScriptManager::registerDefaultBindings ( )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerFunction()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerVariable()

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().

Here is the call graph for this function:

◆ removeIgnoredFile()

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.

◆ requireDeclaredClass()

void Aurora::Lua::ScriptManager::requireDeclaredClass ( const Common::UString name) const
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLuaInstanceForObject()

void Aurora::Lua::ScriptManager::setLuaInstanceForObject ( void *  object,
const TableRef luaInstance 
)

Definition at line 263 of file scriptman.cpp.

References _objectLuaInstances.

◆ unsetLuaInstanceForObject()

void Aurora::Lua::ScriptManager::unsetLuaInstanceForObject ( void *  object)

Definition at line 271 of file scriptman.cpp.

References _objectLuaInstances.

Member Data Documentation

◆ _ignoredFiles

std::set<Common::UString> Aurora::Lua::ScriptManager::_ignoredFiles
private

A list of files that the script subsystem ignores.

Definition at line 123 of file scriptman.h.

Referenced by addIgnoredFile(), isIgnoredFile(), and removeIgnoredFile().

◆ _luaState

lua_State* Aurora::Lua::ScriptManager::_luaState
private

◆ _objectLuaInstances

ObjectLuaInstanceMap Aurora::Lua::ScriptManager::_objectLuaInstances
private

◆ _regNestingLevel

int Aurora::Lua::ScriptManager::_regNestingLevel
private

The documentation for this class was generated from the following files: