![]() |
Lua Utils
Biblioteca utilitária para facilitar a integração de Lua com C++
|
#include <luaProxy.h>
Public Member Functions | |
LuaSimpleProxy (const T &obj) | |
T & | get () |
void * | getClassMetatableID () |
void | populateMetatable (lua_State *L, int index) |
Static Private Member Functions | |
static int | l___gc (lua_State *L) |
Método de coleta de lixo. Deleta o proxy. | |
Private Attributes | |
T | _obj |
Objeto encapsulado. | |
Encapsulates a C++ object so it can be retrieved in Lua C functions. This is the simplest possible implementation of the LuaProxy::Base interface, and its use is equally simple. Let's say you have a C++ object, myObj
of type MyClass
, that you want to assign to a global Lua variable also called myObj
. Here's what you do:
Let's now say that you are in a Lua C function, and you want to check that the first parameter is a C++ object of type MyClass
. Here's what you do:
When a LuaSimpleProxy's garbage collection metamethod is invoked, it will be deleted. Therefore, it is not necessary for you to delete the LuaSimpleProxy if you push it onto a Lua state.
The proxy will actually create a copy of the supplied object; i.e., it follows pass-by-value semantics. If you need pass-by-reference semantics, declare the proxy as containing a pointer, e.g.:
|
inline |
Encapsulates the supplied object in a Lua proxy.
|
inline |
|
inlinevirtual |
A scriptable object should return here a unique ID for its class. This will be used to identify the class's metatable once it has been created.
Implements LuaProxy::Base.
|
inlinevirtual |
The value at index in the Lua stack is guaranteed to be a table (which may or may not be empty; see below). This method must fill it with events/metamethods (set functions and tables in the table using strings as keys) so that userdata representing objects of this class will behave appropriately.
For convenience, the metatable will already have an "__index" event set to an empty table, so you can start filling that out immediately.
Hint: Design your classes so that the first thing in the method's body being an invocation of __super::populateMetatable() ensures proper inheritance.
Implements LuaProxy::Base.