[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Object binding system vs LUA_REGISTRYINDEX
- From: "Brian Weed" <bw@...>
- Date: Tue, 17 Apr 2007 19:02:48 -0400
First, let me say thanks to everyone for the quick replies....
To sort of answer everyone at once:
In lua, my object is a table that contains a userdata that wraps my C++
object (based somewhat on Luna and LuaCD.h).
When the table has no more references it is garbage collected and the
__gc method for my userdata is called. (Before I added the code to store
the table in the registry, everything was working fine...we have shipped
several products using this object binding system).
I can't remove the entry from the Lua environment table in the objects
destructor because the object is no longer destructed, which is exactly
Reading further, it seems as though my problem would be solved if I
could store the lua table as a weak value in the registry...is that
I will also look at userdata environments.
Gé Weijers wrote:
I wonder if I'm missing something. Couldn't you just remove the entry
from the Lua environment table when the C++ object's destructor is
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.