lua-users home
lua-l archive

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

On 3/14/06, SevenThunders <> wrote:

I have two favorite ways to improve productivity when coding in C. The first
is the use of a scripting language for the high level logic and the second
is the use of a garbage collector to free one from the drudgery and bug
generation of manual memory management.

Unfortunately it is not trivial to attempt to use both techniques at the
same time.  For example I have a C library that uses garbage collection
(Hans Boehm et. al.) to manage a complex tree-like data structure.  I wish
to expose the C library to Lua so that I can script a lot of my test
routines and perform debugging in LUA.  The problem is that the Hans Boehm
gc utilities can not see any of the C pointers that are being held in Lua
and thus all my C objects are eventually collected even though I am still
'using' them.

This sounds like all you need to do is create a Lua user data type and hook the __gc metamethod to your C garbage collector.  That way the objects persist because they exist in Lua as a user data type and when the Lua garbage collector collects the object it will be released in both places.

// Chris