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

Detailed Description

This class provides utilities for exposing C++ classes to Lua scripts, allowing Lua code to create and interact with C++ objects. It manages the registration of classes, object lifetime, and inheritance relationships.

#include <luaBinder.h>

Public Member Functions

 DtLuaBinder (lua_State &L)
 
 ~DtLuaBinder ()
 
void registerClass (const std::string &className, const std::string &baseClass, const luaL_Reg *memberFuncList, const luaL_Reg *publicFuncList)
 
void pushClassInstance (void *ptr, const std::string &className)
 
void * checkClassInstance (int index, const std::string &className)
 
void * checkClassInstance (DtLuaObject &obj, const std::string &className)
 
void storeClassInstance (void *ptr, const std::string &className, const std::string &variableName)
 
int absIndex (int index)
 

Protected Attributes

lua_State * myState
 

Constructor & Destructor Documentation

◆ DtLuaBinder()

makVre::DtLuaBinder::DtLuaBinder ( lua_State & L)

Constructor.

Parameters
LThe Lua state to bind to

◆ ~DtLuaBinder()

makVre::DtLuaBinder::~DtLuaBinder ( )

Destructor.

Member Function Documentation

◆ registerClass()

void makVre::DtLuaBinder::registerClass ( const std::string & className,
const std::string & baseClass,
const luaL_Reg * memberFuncList,
const luaL_Reg * publicFuncList )

Registers a C++ class with Lua.

This method exposes a C++ class to Lua, defining its name, inheritance, and available methods. It creates the necessary metatables and registration structures for the class.

Parameters
classNameThe name to use for this class in Lua
baseClassThe name of the parent class (empty string if none)
memberFuncListArray of member functions that instances can call
publicFuncListArray of static functions accessible through the class table

◆ pushClassInstance()

void makVre::DtLuaBinder::pushClassInstance ( void * ptr,
const std::string & className )

Creates and pushes a Lua representation of a C++ object onto the stack.

This method takes a C++ object pointer and pushes a Lua userdata representing that object onto the Lua stack. The userdata will have the appropriate metatable for the object's class.

Note
This should only be used in binding/glue functions
Parameters
ptrPointer to the C++ object
classNameThe class name of the object

◆ checkClassInstance() [1/2]

void * makVre::DtLuaBinder::checkClassInstance ( int index,
const std::string & className )

Validates and extracts a C++ object pointer from a Lua value.

Checks if the Lua value at the specified stack index is a userdata with a metatable matching the given class name (or a derived class). If it is, returns the pointer to the C++ object.

Note
This should only be used in binding/glue functions
Parameters
indexThe stack index of the Lua value to check
classNameThe expected class name of the object
Returns
Pointer to the C++ object or NULL if validation fails

◆ checkClassInstance() [2/2]

void * makVre::DtLuaBinder::checkClassInstance ( DtLuaObject & obj,
const std::string & className )

Validates and extracts a C++ object pointer from a Lua object.

Note
This should only be used in binding/glue functions
Parameters
objThe Lua object to check
classNameThe expected class name of the object
Returns
Pointer to the C++ object or NULL if validation fails

◆ storeClassInstance()

void makVre::DtLuaBinder::storeClassInstance ( void * ptr,
const std::string & className,
const std::string & variableName )

Stores a C++ object as a global Lua variable.

Creates a Lua userdata for the specified C++ object and assigns it to a global variable with the given name.

Parameters
ptrPointer to the C++ object
classNameThe class name of the object
variableNameThe name of the global variable to create

◆ absIndex()

int makVre::DtLuaBinder::absIndex ( int index)

Converts a relative stack index to an absolute index.

Parameters
indexThe stack index to convert (positive or negative)
Returns
The absolute (positive) stack index

Member Data Documentation

◆ myState

lua_State* makVre::DtLuaBinder::myState
protected

The Lua state this binder is associated with.


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