In the newest LuaBridge version you can use RefCountedPtr
for example:
some C++ definition
struct A {};
static RefCountedPtr<A> SomeA() {
return RefCountedPtr<A>(new A);
}
and the binding:
luabridge::getGlobalNamespace(L)
.beginClass<A>("A")
.addConstructor< void (*) (), RefCountedPtr<A> >()
.endClass()
.addFunction("SomeA",&SomeA);
now you can return A
objects safely and pass them to other Lua-bound functions as RefCountedPtr<A>
in lua you can then use it like that:
local a=A()
--do something with a...
local b=SomeA()
--do something with b...