|
VR-Engage
2.2
|
This class encapsulates a Lua state and provides methods for executing scripts, accessing Lua objects, and converting between C++ and Lua data types. It also manages the encoder/decoder registry for type conversion.
#include <luaState.h>
Public Member Functions | |
| DtLuaState () | |
| DtLuaState (lua_State &L) | |
| virtual | ~DtLuaState () |
| DtLuaState & | operator= (const DtLuaState &orig) |
| lua_State * | state () |
| virtual bool | hasObject (const std::string &name) |
| virtual DtLuaObject | findObject (const std::string &name) |
| virtual bool | doFile (const std::string &filename) |
| virtual bool | doScript (const std::string &data) |
| template<typename RT> | |
| RT | get (int stackIndex) |
| template<typename RT> | |
| RT | get (const std::string &name, bool resolveDots=true) |
| template<typename T> | |
| void | push (const T &data) |
| template<typename T> | |
| bool | store (const std::string &name, const T &data) |
| virtual DtLuaObject | createTable (int narr=0, int nrec=0) |
| virtual void | clearStack () |
| virtual void | stackDump () |
| virtual void | forceGarbageCollection () |
| virtual bool | getItemOnStack (const std::string &name, bool resolveDots=true) |
| virtual bool | topStackValueOk () |
| virtual int | stackSize () |
Static Public Member Functions | |
| template<typename T> | |
| static void | addEncoder (DtBaseEncoder *encoder) |
| template<typename T> | |
| static void | addDecoder (DtBaseDecoder *decoder) |
| template<typename T> | |
| static void | addEncoder (DtBaseEncoder *encoder) |
| template<typename T> | |
| static void | addDecoder (DtBaseDecoder *decoder) |
Protected Types | |
| using | EncoderMap = std::map<std::string, DtBaseEncoder*> |
| using | DecoderMap = std::map<std::string, DtBaseDecoder*> |
Protected Member Functions | |
| virtual void | printValue (int index) |
| virtual void | printTable (int index) |
Static Protected Member Functions | |
| static void | initEncoders () |
| static void | initDecoders () |
Protected Attributes | |
| lua_State * | myState |
| bool | myNeedToCloseState |
Static Protected Attributes | |
| static EncoderMap | theEncoders |
| static DecoderMap | theDecoders |
| static bool | theInitializedEncoderDecoders |
Private Member Functions | |
| DtLuaState (const DtLuaState &orig) | |
|
protected |
Type definition for the encoder registry map.
|
protected |
Type definition for the decoder registry map.
|
private |
Copy constructor (not implemented)
Copying a Lua state is not supported
References DtLuaState().
Referenced by DtLuaState(), and operator=().
| makVre::DtLuaState::DtLuaState | ( | ) |
Default constructor.
Creates a new Lua state and initializes it with standard libraries
| makVre::DtLuaState::DtLuaState | ( | lua_State & | L | ) |
Constructor with existing Lua state.
| L | Reference to an existing Lua state to use |
|
virtual |
Virtual destructor.
Closes the Lua state if it was created by this object
| DtLuaState & makVre::DtLuaState::operator= | ( | const DtLuaState & | orig | ) |
Assignment operator.
| orig | The Lua state to copy from |
Copies the Lua state reference but does not copy the actual Lua state
References DtLuaState().
| lua_State * makVre::DtLuaState::state | ( | ) |
Gets the underlying Lua state.
|
virtual |
Checks if an object exists in the Lua state.
| name | Name of the object to check for |
|
virtual |
Finds and returns a Lua object.
| name | Name of the object to find |
|
virtual |
Executes a Lua script from a file.
| filename | Path to the Lua script file |
|
virtual |
| RT makVre::DtLuaState::get | ( | int | stackIndex | ) |
Gets a value from the Lua stack and converts it to a C++ type.
| RT | Return type to convert the Lua value to |
| stackIndex | Index on the Lua stack |
| std::string | if a decoder for the requested type is not found |
References DtASSERT, makVre::DtTypeDecoder< T >::get(), myState, and theDecoders.
Referenced by doScript(), and get().
| RT makVre::DtLuaState::get | ( | const std::string & | name, |
| bool | resolveDots = true ) |
Gets a named value from Lua and converts it to a C++ type.
| RT | Return type to convert the Lua value to |
| name | Name of the Lua variable/object to get |
| resolveDots | Whether to resolve dotted names (e.g., 'table.field') |
| std::string | if the variable doesn't exist or a decoder for the type is not found |
References get(), getItemOnStack(), and myState.
| void makVre::DtLuaState::push | ( | const T & | data | ) |
Pushes a C++ value onto the Lua stack.
| T | Type of the value to push |
| data | The value to push onto the Lua stack |
| std::string | if an encoder for the specified type is not found |
References DtASSERT, myState, makVre::DtTypeEncoder< T >::push(), and theEncoders.
Referenced by doScript(), makVre::DtLuaObject::setField(), and makVre::DtLuaObject::setField().
| bool makVre::DtLuaState::store | ( | const std::string & | name, |
| const T & | data ) |
Stores a C++ value as a named variable in Lua.
| T | Type of the value to store |
| name | Name to give the variable in Lua |
| data | The value to store |
|
virtual |
Creates a new Lua table.
| narr | Pre-allocated array slots (optimization hint) |
| nrec | Pre-allocated record slots (optimization hint) |
|
virtual |
Clears the Lua stack.
Removes all items from the Lua stack
|
virtual |
Dumps the contents of the Lua stack for debugging.
Prints each item on the stack to standard output
|
virtual |
Forces a full Lua garbage collection cycle.
|
static |
Registers an encoder for a specific C++ type.
| T | The C++ type to register an encoder for |
| encoder | Pointer to the encoder implementation |
|
static |
Registers a decoder for a specific C++ type.
| T | The C++ type to register a decoder for |
| decoder | Pointer to the decoder implementation |
|
virtual |
Retrieves a named item and pushes it onto the stack.
| name | Name of the item to retrieve |
| resolveDots | Whether to resolve dotted names (e.g., 'table.field') |
Referenced by get().
|
virtual |
Checks if the top stack value is valid.
|
virtual |
Gets the current size of the Lua stack.
|
protectedvirtual |
Prints a single value from the stack for debugging.
| index | Index of the value to print |
|
protectedvirtual |
Prints a table from the stack for debugging.
| index | Index of the table to print |
|
staticprotected |
Initializes the standard encoders.
|
staticprotected |
Initializes the standard decoders.
|
static |
References theEncoders.
|
static |
References theDecoders.
|
protected |
|
protected |
Flag indicating if the state should be closed on destruction.
|
staticprotected |
Static map of type names to encoder implementations.
Referenced by addEncoder(), and push().
|
staticprotected |
Static map of type names to decoder implementations.
Referenced by addDecoder(), and get().
|
staticprotected |
Flag indicating if encoders and decoders have been initialized.