How do you get a reference to a C++ object, from another C++ object, inside a Lua script? I don't really know how to summarize that in words properly, so let me elaborate with a Lua example first:
function doSomething()
compo = a:getComponent()
compo:setVariable(0)
end
a is a C++ object, and the function getComponent returns a pointer:
// inside A.h
Component* A::getComponent();
It seems the problem is that getComponent()
is passing a copy of the Component object to Lua, instead of a reference. I come across the same problem with every function that returns a pointer, Lua cannot modify the original object.
Object a seems to be working correctly, if I modify a variable from within Lua, it's outcome is mirrored in C++. Both A and component are bound to Lua already, as well as the required methods.
Am I missing something syntactically or is there more to it than that?
I am using luabind, Lua 5.1, and MinGW. Thanks for any help in advance.
EDIT
Here is the luabind code. I summarized it because there's a bunch of other binds that have no relation to the problem:
luabind::class_<A>("A")
.def("getComponent", &A::getComponent)