Hey,
I am currently using LuaBridge as the C++ interface to Lua, and I'm having trouble passing a simple pointer to Lua (as a unique identifier for an object) and then back again. The Lua script calls "object(...)" which returns a pointer, and the pointer is stored in a local: "local obj = tbl.object(....)". If I then proceed to use the variable obj for anything, it's always "nil". What's going on here?
I would think this was the most basic and repeating pattern in Lua scripting to use memory addresses as identifiers as well as simplify access to engine internals.
static Object* object(int x, int y, int w, int h, int floor) {
auto obj = std::make_unique<Object> (gworld(), x, y, w, h, floor);
gworld().objects().add(std::move(obj));
return obj.get();
}
...
static void object_frame(LuaRef id, int tex, int x, int y, int w, int h) {
printf("object_frame(%p, tex=%d)\n", id.cast<Object*> (), tex);
}
...
gns.beginNamespace("dm")
.addFunction("object", object)
...
local obj = dm.object(x,y, 8,8, 0)
dm.object_frame(obj, gui.tex, 80 + 9*idx,0, 9,8)
The value of id, which should just be a memory address, in the "object_frame" function is always nil.