lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 3/14/06, SevenThunders <mattcbro@earthlink.net> wrote:

That is really interesting.  I've used metatables for extending LUA syntax to
C datatypes but I didn't realize you could attach garbage collector actions
to them.  This approach is quite interesting.  It doesn't directly solve my
problem in that it doesn't expose the C pointers stored in LUA data
structures to the gc in C.   Thus the C garbage collector will still see the
C objects stored in LUA as unreachable.  However what your solution does do
is to allow the LUA gc to automatically deallocate objects from C using say
the standard malloc and free approach.  That's pretty close to having a
garbage collector, though all the destructors will have to be written
explicitly and on the C side of things the C garbage collector will have to
be dropped or disabled.


Actually, I wasn't suggesting dropping the C garbage collector.  I was suggesting making the Lua __gc metamethod call the C garbage collectors  "release()" or whatever on the C pointer than exists in the user type.  I don't think I can explain it very well but hopefully you get the idea.

The reverse should also work if your C garbage collector has a hook when items are collected.  You attach the C garbage collector's equivalent to __gc to a Lua variable and have it release the Lua objects as needed.

--
// Chris