lua-users home
lua-l archive

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


If user data needs to include a reference to Lua data, there isn't a
particularly great way to do it. In particular, weak tables and registry
entries all seem potentially prone to cycle problems depending on how
garbage collection for weak tables works. For example, if userdata A points
to B via a reference and B points to A, then A will never have its __gc
function called because the registry gets us to B which gets us to A. Since
the __gc function never gets called, we will never get rid of the ref for B.

How complicated would it be to allow userdata to consist of two sections?
The first section would be a series of TObjects of a length generally
specified in the userdata constructor. The rest of the object would consist
of arbitrary data as it does now. Even better would be a way to specify an
offset and count for the pointers so that one could position them a bit more
freely, but this comes with extra overhead. The garbage collector could then
trace the references from a user data just as it traces references from Lua
tables.

Mark

P.S. I'm in the midst of trying to build a system in which Lua, Objective-C,
and C++ are all essentially first-class citizens. It imposes some
interesting complications.