BARE2D
BARE2D::LuaScriptContextWrapper Class Reference

#include <LuaScript.hpp>

+ Collaboration diagram for BARE2D::LuaScriptContextWrapper:

Public Member Functions

 LuaScriptContextWrapper ()
 
 ~LuaScriptContextWrapper ()
 
void init (lua_State *parentState, LuaScript *script)
 Creates and initializes all the necessary bits. More...
 
void destroy ()
 Cleans up. More...
 
void start ()
 Starts the script. More...
 
void update ()
 Updates the script - decreases delay counter, checks if it is finished, etc. More...
 
bool isCompleted ()
 Returns m_completed. More...
 

Protected Member Functions

void loadLua (std::string &luaStr)
 Loads and compiles the given Lua script. Also, sets m_scriptReference to the index of the compiled script in the registry. More...
 
void createThread ()
 Creates the m_state variable as a thread, or subroutine of the parent. More...
 

Protected Attributes

lua_State * m_state = nullptr
 
lua_State * m_parent = nullptr
 
bool m_yielded = false
 
unsigned int m_remainingDelay = 0
 
bool m_completed = false
 
int m_scriptReference = LUA_REFNIL
 
int m_threadReference = LUA_REFNIL
 

Detailed Description

Definition at line 31 of file LuaScript.hpp.

Constructor & Destructor Documentation

◆ LuaScriptContextWrapper()

BARE2D::LuaScriptContextWrapper::LuaScriptContextWrapper ( )

Definition at line 15 of file LuaScript.cpp.

◆ ~LuaScriptContextWrapper()

BARE2D::LuaScriptContextWrapper::~LuaScriptContextWrapper ( )

Definition at line 18 of file LuaScript.cpp.

Member Function Documentation

◆ createThread()

void BARE2D::LuaScriptContextWrapper::createThread ( )
protected

Creates the m_state variable as a thread, or subroutine of the parent.

Definition at line 32 of file LuaScript.cpp.

References BARE2D::LUA_FAILURE, m_parent, m_state, m_threadReference, and BARE2D::throwError().

Referenced by init().

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

◆ destroy()

void BARE2D::LuaScriptContextWrapper::destroy ( )

Cleans up.

Definition at line 45 of file LuaScript.cpp.

References m_completed, and m_state.

Referenced by update().

+ Here is the caller graph for this function:

◆ init()

void BARE2D::LuaScriptContextWrapper::init ( lua_State *  parentState,
LuaScript script 
)

Creates and initializes all the necessary bits.

Parameters
idThe ID of the script, which was assigned from the LuaScriptQueue
parentStateThe masterstate, generally, although I suppose it could be others.

Definition at line 21 of file LuaScript.cpp.

References createThread(), loadLua(), m_parent, and BARE2D::LuaScript::m_script.

Referenced by BARE2D::LuaScriptEngine::createLuaContext().

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

◆ isCompleted()

bool BARE2D::LuaScriptContextWrapper::isCompleted ( )

Returns m_completed.

Definition at line 141 of file LuaScript.cpp.

References m_completed.

◆ loadLua()

void BARE2D::LuaScriptContextWrapper::loadLua ( std::string &  luaStr)
protected

Loads and compiles the given Lua script. Also, sets m_scriptReference to the index of the compiled script in the registry.

Parameters
luaStrThe script to compile.

Definition at line 120 of file LuaScript.cpp.

References BARE2D::LUA_FAILURE, m_scriptReference, m_state, and BARE2D::throwError().

Referenced by init().

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

◆ start()

void BARE2D::LuaScriptContextWrapper::start ( )

Starts the script.

Definition at line 56 of file LuaScript.cpp.

References BARE2D::LUA_FAILURE, m_scriptReference, m_state, and BARE2D::throwError().

Referenced by BARE2D::LuaScriptEngine::update().

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

◆ update()

void BARE2D::LuaScriptContextWrapper::update ( )

Updates the script - decreases delay counter, checks if it is finished, etc.

Definition at line 80 of file LuaScript.cpp.

References destroy(), BARE2D::LUA_FAILURE, m_completed, m_remainingDelay, m_state, m_yielded, and BARE2D::throwError().

+ Here is the call graph for this function:

Field Documentation

◆ m_completed

bool BARE2D::LuaScriptContextWrapper::m_completed = false
protected

Definition at line 85 of file LuaScript.hpp.

Referenced by destroy(), isCompleted(), and update().

◆ m_parent

lua_State* BARE2D::LuaScriptContextWrapper::m_parent = nullptr
protected

Definition at line 78 of file LuaScript.hpp.

Referenced by createThread(), and init().

◆ m_remainingDelay

unsigned int BARE2D::LuaScriptContextWrapper::m_remainingDelay = 0
protected

Definition at line 82 of file LuaScript.hpp.

Referenced by update().

◆ m_scriptReference

int BARE2D::LuaScriptContextWrapper::m_scriptReference = LUA_REFNIL
protected

Definition at line 88 of file LuaScript.hpp.

Referenced by loadLua(), and start().

◆ m_state

lua_State* BARE2D::LuaScriptContextWrapper::m_state = nullptr
protected

Definition at line 76 of file LuaScript.hpp.

Referenced by createThread(), destroy(), loadLua(), start(), and update().

◆ m_threadReference

int BARE2D::LuaScriptContextWrapper::m_threadReference = LUA_REFNIL
protected

Definition at line 90 of file LuaScript.hpp.

Referenced by createThread().

◆ m_yielded

bool BARE2D::LuaScriptContextWrapper::m_yielded = false
protected

Definition at line 81 of file LuaScript.hpp.

Referenced by update().


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