[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Object binding system vs LUA_REGISTRYINDEX
- From: Asko Kauppi <askok@...>
- Date: Wed, 18 Apr 2007 13:15:54 +0300
Lua has closures, which are really nice. You can combine a function
(shared by all your callbacks) with the actual data being processed
as an upvalue (different per callback). You can usually have this
done on the Lua side of things.
If I got your problem right, this would allow a solution without any
need to have references in the registry?
Brian Weed kirjoitti 18.4.2007 kello 0:28:
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++