[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: linking tables to C++ objects?
- From: Sam Roberts <sroberts@...>
- Date: Tue, 27 Feb 2007 14:08:40 -0800
On Tue, Feb 27, 2007 at 11:41:51AM -0800, Graham Wakefield wrote:
> I see. In the globals table you have something like this
>
> LUA_GLOBALSINDEX.V_MAIN._objects[ptr] = (some lua object, e.g. table).
>
> In my case I'm using the registry, rather than a table inside the
> globals table, but its pretty much the same otherwise. The reference
> stored here prevents garbage collection.
No, the _objects table has weak values, look down in luaopen_vortex()
where it is created.
When the only remaining references to an object are "weak", the table
entries (both key and value) with the weak references are removed, and
the object is garbage collected.
> I also notice you use luaL_ref to retain the location of lua
> functions for later callbacks from C; I hadn't used luaL_ref before,
> but I wonder whether this might be a better solution to my problem.
Could be. I had to use them in some places because of the ways callbacks
are specified as anonymous (lua) functions, and the structure of the
Vortex callback system.
Note that unlike _objects, a weak-valued table, references really will
prevent GC.
I found it a bit tricky. It can be hard to coordinate the C world's view
of lifetime, and the lua world's.
Anyhow, I would not take swirl as an example of how things "should" be
done, just an experiment to see how they "can" be done. Vortex is
heavily multi-threaded, as well, callbacks mostly happen on ephemeral
threads, which caused too much difficulty. Development on swirl is
stalled.
Sam
- References:
- linking tables to C++ objects?, Graham Wakefield
- Re: linking tables to C++ objects?, David Burgess
- Re: linking tables to C++ objects?, Graham Wakefield
- Re: linking tables to C++ objects?, Graham Wakefield
- Re: linking tables to C++ objects?, Sam Roberts
- Re: linking tables to C++ objects?, Graham Wakefield
- Re: linking tables to C++ objects?, Sam Roberts
- Re: linking tables to C++ objects?, Graham Wakefield
- Re: linking tables to C++ objects?, Sam Roberts
- Re: linking tables to C++ objects?, Graham Wakefield