|
VR-Engage
2.2
|
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 |
| makVre::DtLuaBinder::DtLuaBinder | ( | lua_State & | L | ) |
Constructor.
| L | The Lua state to bind to |
| makVre::DtLuaBinder::~DtLuaBinder | ( | ) |
Destructor.
| 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.
| className | The name to use for this class in Lua |
| baseClass | The name of the parent class (empty string if none) |
| memberFuncList | Array of member functions that instances can call |
| publicFuncList | Array of static functions accessible through the class table |
| 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.
| ptr | Pointer to the C++ object |
| className | The class name of the object |
| 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.
| index | The stack index of the Lua value to check |
| className | The expected class name of the object |
| void * makVre::DtLuaBinder::checkClassInstance | ( | DtLuaObject & | obj, |
| const std::string & | className ) |
Validates and extracts a C++ object pointer from a Lua object.
| obj | The Lua object to check |
| className | The expected class name of the object |
| 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.
| ptr | Pointer to the C++ object |
| className | The class name of the object |
| variableName | The name of the global variable to create |
| int makVre::DtLuaBinder::absIndex | ( | int | index | ) |
Converts a relative stack index to an absolute index.
| index | The stack index to convert (positive or negative) |
|
protected |
The Lua state this binder is associated with.