#include <LuaScriptEngine.hpp>
Collaboration diagram for BARE2D::LuaScriptEngine:Public Member Functions | |
| LuaScriptEngine () | |
| ~LuaScriptEngine () | |
| void | init (std::string luaModulesPath) |
| Initializes the LuaScriptEngine - loads basic modules etc. More... | |
| void | registerModule (std::string filename) |
| Loads and registers (read: runs) the module located at the given file. More... | |
| void | registerCFunction (lua_CFunction function, std::string name) |
| Adds a Lua C Function. This is a function which can be called from inside a Lua script, and executes C/C++ code. More... | |
| void | update () |
| Processes all scripts from the LuaScriptQueue and updates all running scripts. That's pretty much it! More... | |
| lua_State * | getMasterState () |
| Returns a pointer to the master state. More... | |
Static Public Member Functions | |
| template<class T > | |
| static void | addValueToRegistry (lua_State *L, T *value, std::string key) |
| Adds a value to the Lua registry - this lets any C/C++ code use the value stored in the state (it is stored in the state) More... | |
| template<class T > | |
| static T * | getValueFromRegistry (lua_State *L, std::string key) |
Private Member Functions | |
| LuaScriptContextWrapper * | createLuaContext (LuaScript *script) |
| Creates a LuaScriptContextWrapper using the data from script. More... | |
Private Attributes | |
| lua_State * | m_masterState = nullptr |
Definition at line 20 of file LuaScriptEngine.hpp.
| BARE2D::LuaScriptEngine::LuaScriptEngine | ( | ) |
Definition at line 12 of file LuaScriptEngine.cpp.
| BARE2D::LuaScriptEngine::~LuaScriptEngine | ( | ) |
Definition at line 16 of file LuaScriptEngine.cpp.
|
static |
Adds a value to the Lua registry - this lets any C/C++ code use the value stored in the state (it is stored in the state)
| value | A pointer to the value to be added. |
| key | The key to be used to access the value in the registry. |
|
private |
Creates a LuaScriptContextWrapper using the data from script.
| script | A pointer to the LuaScript which we want to create a new Lua state for. |
Definition at line 82 of file LuaScriptEngine.cpp.
References BARE2D::LuaScriptContextWrapper::init(), and m_masterState.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:| lua_State * BARE2D::LuaScriptEngine::getMasterState | ( | ) |
Returns a pointer to the master state.
Definition at line 92 of file LuaScriptEngine.cpp.
References m_masterState.
|
static |
| void BARE2D::LuaScriptEngine::init | ( | std::string | luaModulesPath | ) |
Initializes the LuaScriptEngine - loads basic modules etc.
| The | path to the user-created Lua modules. |
Definition at line 21 of file LuaScriptEngine.cpp.
References BARE2D::LuaFunctions::delay(), m_masterState, BARE2D::LuaFunctions::print(), and registerCFunction().
Here is the call graph for this function:| void BARE2D::LuaScriptEngine::registerCFunction | ( | lua_CFunction | function, |
| std::string | name | ||
| ) |
Adds a Lua C Function. This is a function which can be called from inside a Lua script, and executes C/C++ code.
| function | The function which will be called when the Lua script calls the closure. Follows the form of a std::function<int(lua_State*)>. The lua_State pointer provides a handle to the Lua stack (really, the whole state, but the stack is the most important) which allows the C/C++ program to recieve parameters and add return values. Must return the number of values the function gives back to Lua. See https://www.lua.org/manual/5.1/manual.html#lua_CFunction |
| name | The name by which the Lua code can call the function. |
Definition at line 50 of file LuaScriptEngine.cpp.
References m_masterState.
Referenced by init().
Here is the caller graph for this function:| void BARE2D::LuaScriptEngine::registerModule | ( | std::string | filename | ) |
Loads and registers (read: runs) the module located at the given file.
| filename | The file to load/run. |
Definition at line 45 of file LuaScriptEngine.cpp.
References BARE2D::throwError(), and BARE2D::UNINITIALIZED_FUNCTION.
Here is the call graph for this function:| void BARE2D::LuaScriptEngine::update | ( | ) |
Processes all scripts from the LuaScriptQueue and updates all running scripts. That's pretty much it!
Definition at line 61 of file LuaScriptEngine.cpp.
References BARE2D::LuaContextManager::addContext(), BARE2D::LuaScriptQueue::clearQueue(), createLuaContext(), BARE2D::LuaContextManager::getInstance(), BARE2D::LuaScriptQueue::getInstance(), BARE2D::LuaScriptContextWrapper::start(), and BARE2D::LuaContextManager::update().
Here is the call graph for this function:
|
private |
Definition at line 77 of file LuaScriptEngine.hpp.
Referenced by createLuaContext(), getMasterState(), init(), and registerCFunction().