|Could you give us a bit more information? I believe about everyone who answered you answered a different question :-)|
I can think of two different scenarios:
1) you have a Lua userdata object implemented in C++ that needs a Lua table to represent methods written in Lua. In that case Rici's suggestion would work: store the data in the object's environment. Alternatively (e.g. for Lua 5.0) you could use a separate weak table with your userdata object as the weak key, and the table as the (strong) value. The weak table could be stored in the registry or the module's environment, your choice.
2) you have a C++ object that's not stored as a Lua userdata object. In that case the destructor of your C++ object can remove the reference.
On Apr 17, 2007, at 5:28 PM, Brian Weed wrote:
So, I have this problem with my C++ object binding system. I've recently added code to store the Lua table that represents my C++ object in the lua registry, with the objects pointer as a key. I did this so that I can look up the table from the pointer for C++ to Lua callbacks (i.e. to call a buttons OnClick() method from C++). However, since I'm storing the lua table in the registry, it is no longer garbage collected (since it still has a reference)...I had put the code to remove the reference in the GC method of the object, so of course it never gets called (DOH).
My question is this: How can I store a reference to my lua object (a table) without there being an extra reference to it in Lua so it can be garbage collected?
I'm guessing that there is no official way to store it on the C++ side.