VR-Engage  2.2
Loading...
Searching...
No Matches
makVre::DtLuaObject Class Reference

Detailed Description

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>

Inheritance diagram for makVre::DtLuaObject:
[legend]

Public Member Functions

 DtLuaObject ()
 
 DtLuaObject (lua_State &state, int index)
 
virtual ~DtLuaObject () override
 
 DtLuaObject (const DtLuaObject &orig)
 
DtLuaObjectoperator= (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)
 
DtLuaValueoperator= (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

DtLuaReferencemyReference
 
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
}
 

Constructor & Destructor Documentation

◆ DtLuaObject() [1/3]

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

◆ DtLuaObject() [2/3]

makVre::DtLuaObject::DtLuaObject ( lua_State & state,
int index )

Constructor from Lua stack value.

Parameters
stateThe Lua state containing the object
indexIndex of the object on the Lua stack

References state().

◆ ~DtLuaObject()

virtual makVre::DtLuaObject::~DtLuaObject ( )
overridevirtual

Virtual destructor.

Releases the reference to the Lua object

◆ DtLuaObject() [3/3]

makVre::DtLuaObject::DtLuaObject ( const DtLuaObject & orig)

Copy constructor.

Parameters
origThe source object to copy from

References DtLuaObject().

Member Function Documentation

◆ operator=()

DtLuaObject & makVre::DtLuaObject::operator= ( const DtLuaObject & orig)

Assignment operator.

Parameters
origThe source object to assign from
Returns
Reference to this object

References DtLuaObject().

◆ operator==()

virtual bool makVre::DtLuaObject::operator== ( const DtLuaObject & rhs)
virtual

Equality comparison operator.

Parameters
rhsRight-hand side object to compare with
Returns
True if objects reference the same Lua object, false otherwise

References DtLuaObject(), and get().

◆ get()

template<typename RT>
RT makVre::DtLuaObject::get ( )

Gets the value of this object converted to a C++ type.

Template Parameters
RTThe C++ type to convert the Lua value to
Returns
The Lua value converted to the specified C++ type
Exceptions
std::stringif the object is invalid or conversion fails

References isValid(), myState, push(), and state().

Referenced by operator==().

◆ push()

virtual void makVre::DtLuaObject::push ( ) const
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().

◆ hasField() [1/2]

virtual bool makVre::DtLuaObject::hasField ( const std::string & name,
bool resolveDots = true )
virtual

Checks if the table has a field with the given name.

Parameters
nameThe name of the field to check for
resolveDotsIf true, handles dotted notation for nested tables (e.g., "table.field")
Returns
True if the field exists, false otherwise

Referenced by makVre::DtCigiSession::findConfigParam(), makVre::DtInitTable::findDataOr(), and makVre::DtWeaponResourceLogic::lookUpField().

◆ hasField() [2/2]

virtual bool makVre::DtLuaObject::hasField ( int index)
virtual

Checks if the table has a field at the given numeric index.

Parameters
indexThe numeric index to check
Returns
True if the field exists, false otherwise

◆ operator[]() [1/2]

virtual DtLuaObject makVre::DtLuaObject::operator[] ( std::string name)
virtual

Gets a field by name.

Parameters
nameThe name of the field to retrieve
Returns
A new DtLuaObject referencing the field

References DtLuaObject().

◆ operator[]() [2/2]

virtual DtLuaObject makVre::DtLuaObject::operator[] ( int index)
virtual

Gets a field by numeric index.

Parameters
indexThe numeric index of the field to retrieve
Returns
A new DtLuaObject referencing the field

References DtLuaObject().

◆ tableSize()

virtual int makVre::DtLuaObject::tableSize ( )
virtual

Gets the number of elements in the table.

Returns
The number of elements in the table

◆ keys()

std::vector< std::string > makVre::DtLuaObject::keys ( )

Gets all string keys in the table.

Returns
Vector of all string keys in the table

References setField().

◆ setField() [1/2]

template<typename T>
void makVre::DtLuaObject::setField ( const std::string & name,
const T & val )

Sets a field value by name.

Template Parameters
TThe C++ type of the value to set
Parameters
nameThe name of the field to set
valThe value to set the field to
Exceptions
std::stringif 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().

◆ setField() [2/2]

template<typename T>
void makVre::DtLuaObject::setField ( int index,
const T & val )

Sets a field value by numeric index.

Template Parameters
TThe C++ type of the value to set
Parameters
indexThe numeric index of the field to set
valThe value to set the field to

References isValid(), LOG_WARN, myState, makVre::DtLuaValue::myType, push(), makVre::DtLuaState::push(), makVre::DtLuaValue::SCRIPT_TABLE, and setTable().

◆ state()

virtual lua_State * makVre::DtLuaObject::state ( )
virtual

Gets the Lua state associated with this object.

Returns
Pointer to the Lua state

Referenced by makVre::DtInitTable::DtInitTable(), makVre::DtLuaFunction::DtLuaFunction(), DtLuaObject(), makVre::DtInitTable::findData(), makVre::DtInitTable::findData(), and get().

◆ serialize()

virtual std::string makVre::DtLuaObject::serialize ( )
virtual

Serializes the object to a string representation.

Returns
String representation of the Lua object

◆ isValid()

virtual bool makVre::DtLuaObject::isValid ( ) const
virtual

Checks if this object is valid.

Returns
True if the object is valid, false otherwise

An object is valid if it has a valid Lua state and reference

Referenced by makVre::DtCigiSession::findConfigParam(), get(), setField(), and setField().

◆ getItemOnStack() [1/2]

virtual bool makVre::DtLuaObject::getItemOnStack ( const std::string & name,
bool resolveDots )
protectedvirtual

Retrieves a named item from the table and pushes it onto the stack.

Parameters
nameThe name of the item to retrieve
resolveDotsIf true, handles dotted notation for nested tables
Returns
True if the item was found and pushed, false otherwise

Referenced by makVre::DtInitTable::findData(), and makVre::DtInitTable::findData().

◆ getItemOnStack() [2/2]

virtual bool makVre::DtLuaObject::getItemOnStack ( int index)
protectedvirtual

Retrieves an indexed item from the table and pushes it onto the stack.

Parameters
indexThe numeric index of the item to retrieve
Returns
True if the item was found and pushed, false otherwise

◆ setTable()

virtual void makVre::DtLuaObject::setTable ( int index)
protectedvirtual

Sets a table field with values already on the Lua stack.

Parameters
indexThe stack index of the table

This method expects the key and value to already be on the stack

Referenced by setField(), and setField().

Member Data Documentation

◆ myReference

DtLuaReference* makVre::DtLuaObject::myReference
protected

Reference to the Lua object.

◆ myState

lua_State* makVre::DtLuaObject::myState
protected

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