|
VR-Engage
2.2
|
This class provides a C++ interface to Lua objects, primarily tables. It allows for retrieval and manipulation of Lua values through C++ methods, simplifying the interaction between C++ and Lua code.
#include <luaObject.h>
Public Member Functions | |
| DtLuaObject () | |
| DtLuaObject (lua_State &state, int index) | |
| virtual | ~DtLuaObject () override |
| DtLuaObject (const DtLuaObject &orig) | |
| DtLuaObject & | operator= (const DtLuaObject &orig) |
| virtual bool | operator== (const DtLuaObject &rhs) |
| template<typename RT> | |
| RT | get () |
| virtual void | push () const |
| virtual lua_State * | state () |
| virtual std::string | serialize () |
| virtual bool | isValid () const |
Table Access Methods | |
Methods for accessing table fields | |
| virtual bool | hasField (const std::string &name, bool resolveDots=true) |
| virtual bool | hasField (int index) |
| virtual DtLuaObject | operator[] (std::string name) |
| virtual DtLuaObject | operator[] (int index) |
| virtual int | tableSize () |
| std::vector< std::string > | keys () |
| template<typename T> | |
| void | setField (const std::string &name, const T &val) |
| template<typename T> | |
| void | setField (int index, const T &val) |
Public Member Functions inherited from makVre::DtLuaValue | |
| virtual ScriptDataTypeEnum | type () const |
| virtual std::string | typeName () const |
| DtLuaValue () | |
| DtLuaValue (bool v) | |
| DtLuaValue (int v) | |
| DtLuaValue (float v) | |
| DtLuaValue (double v) | |
| DtLuaValue (const std::string &v) | |
| DtLuaValue (const char *v) | |
| DtLuaValue (void *v) | |
| virtual | ~DtLuaValue () |
| DtLuaValue (const DtLuaValue &orig) | |
| DtLuaValue & | operator= (const DtLuaValue &orig) |
| virtual bool | isNil () const |
| virtual bool | isBool () const |
| virtual bool | isInt () const |
| virtual bool | isFloat () const |
| virtual bool | isDouble () const |
| virtual bool | isString () const |
| virtual bool | isPointer () const |
| virtual bool | isTable () const |
| virtual bool | isFunction () const |
| virtual bool | boolValue () const |
| virtual int | intValue () const |
| virtual float | floatValue () const |
| virtual double | doubleValue () const |
| virtual std::string | stringValue () const |
| virtual void * | pointerValue () const |
Protected Member Functions | |
| virtual bool | getItemOnStack (const std::string &name, bool resolveDots) |
| virtual bool | getItemOnStack (int index) |
| virtual void | setTable (int index) |
Protected Attributes | ||
| DtLuaReference * | myReference | |
| lua_State * | myState | |
Protected Attributes inherited from makVre::DtLuaValue | ||
| ScriptDataTypeEnum | myType | |
| union { | ||
| bool myBool | ||
| int myInt | ||
| float myFloat | ||
| double myDouble | ||
| const char * myString | ||
| void * myPtr | ||
| }; | ||
Additional Inherited Members | |
Public Types inherited from makVre::DtLuaValue | |
| enum | ScriptDataTypeEnum { SCRIPT_NIL , SCRIPT_BOOL , SCRIPT_INT , SCRIPT_FLOAT , SCRIPT_DOUBLE , SCRIPT_STRING , SCRIPT_POINTER , SCRIPT_FUNCTION , SCRIPT_TABLE } |
| makVre::DtLuaObject::DtLuaObject | ( | ) |
Default constructor.
Creates an empty, invalid Lua object reference
Referenced by makVre::DtLuaFunction::DtLuaFunction(), DtLuaObject(), makVre::DtLuaFunction::operator=(), operator=(), operator==(), operator[](), and operator[]().
| makVre::DtLuaObject::DtLuaObject | ( | lua_State & | state, |
| int | index ) |
Constructor from Lua stack value.
| state | The Lua state containing the object |
| index | Index of the object on the Lua stack |
References state().
|
overridevirtual |
Virtual destructor.
Releases the reference to the Lua object
| makVre::DtLuaObject::DtLuaObject | ( | const DtLuaObject & | orig | ) |
| DtLuaObject & makVre::DtLuaObject::operator= | ( | const DtLuaObject & | orig | ) |
Assignment operator.
| orig | The source object to assign from |
References DtLuaObject().
|
virtual |
Equality comparison operator.
| rhs | Right-hand side object to compare with |
References DtLuaObject(), and get().
| RT makVre::DtLuaObject::get | ( | ) |
Gets the value of this object converted to a C++ type.
| RT | The C++ type to convert the Lua value to |
| std::string | if the object is invalid or conversion fails |
References isValid(), myState, push(), and state().
Referenced by operator==().
|
virtual |
Pushes this object onto the Lua stack.
This method pushes a reference to the Lua object onto the Lua stack for operations that require the object to be on the stack.
Referenced by get(), setField(), and setField().
|
virtual |
Checks if the table has a field with the given name.
| name | The name of the field to check for |
| resolveDots | If true, handles dotted notation for nested tables (e.g., "table.field") |
Referenced by makVre::DtCigiSession::findConfigParam(), makVre::DtInitTable::findDataOr(), and makVre::DtWeaponResourceLogic::lookUpField().
|
virtual |
Checks if the table has a field at the given numeric index.
| index | The numeric index to check |
|
virtual |
Gets a field by name.
| name | The name of the field to retrieve |
References DtLuaObject().
|
virtual |
Gets a field by numeric index.
| index | The numeric index of the field to retrieve |
References DtLuaObject().
|
virtual |
Gets the number of elements in the table.
| std::vector< std::string > makVre::DtLuaObject::keys | ( | ) |
Gets all string keys in the table.
References setField().
| void makVre::DtLuaObject::setField | ( | const std::string & | name, |
| const T & | val ) |
Sets a field value by name.
| T | The C++ type of the value to set |
| name | The name of the field to set |
| val | The value to set the field to |
| std::string | if the object is invalid or not a table |
References isValid(), LOG_FATAL, myState, makVre::DtLuaValue::myType, push(), makVre::DtLuaState::push(), makVre::DtLuaValue::SCRIPT_TABLE, and setTable().
Referenced by keys().
| void makVre::DtLuaObject::setField | ( | int | index, |
| const T & | val ) |
Sets a field value by numeric index.
| T | The C++ type of the value to set |
| index | The numeric index of the field to set |
| val | The value to set the field to |
References isValid(), LOG_WARN, myState, makVre::DtLuaValue::myType, push(), makVre::DtLuaState::push(), makVre::DtLuaValue::SCRIPT_TABLE, and setTable().
|
virtual |
Gets the Lua state associated with this object.
Referenced by makVre::DtInitTable::DtInitTable(), makVre::DtLuaFunction::DtLuaFunction(), DtLuaObject(), makVre::DtInitTable::findData(), makVre::DtInitTable::findData(), and get().
|
virtual |
Serializes the object to a string representation.
|
virtual |
Checks if this object is valid.
An object is valid if it has a valid Lua state and reference
Referenced by makVre::DtCigiSession::findConfigParam(), get(), setField(), and setField().
|
protectedvirtual |
Retrieves a named item from the table and pushes it onto the stack.
| name | The name of the item to retrieve |
| resolveDots | If true, handles dotted notation for nested tables |
Referenced by makVre::DtInitTable::findData(), and makVre::DtInitTable::findData().
|
protectedvirtual |
Retrieves an indexed item from the table and pushes it onto the stack.
| index | The numeric index of the item to retrieve |
|
protectedvirtual |
Sets a table field with values already on the Lua stack.
| index | The stack index of the table |
This method expects the key and value to already be on the stack
Referenced by setField(), and setField().
|
protected |
Reference to the Lua object.
|
protected |
Pointer to the Lua state.
Referenced by makVre::DtInitTable::findData(), makVre::DtInitTable::findData(), get(), setField(), and setField().