lua-users home
lua-l archive

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


2012/1/3 Dirk Laurie <dirk.laurie@gmail.com>:
> 2012/1/3 Patrick Rapin <toupie300@gmail.com>:
>
>> You can take the address of the full userdata block, push the address
>> on the stack as a light userdata, and use that light userdata as a key
>> to store the full one into the registry (or any other table).
>
> That will solve the problem underlying my post.  My userdata structure
> contains pointers to other userdata, and I need functions returning
> those to Lua as full userdata.

What you can do to avoid that centralized index table (for light udata
to full udata conversion) is to store double references in your
userdata, one as pointer in the C structure, and one as a Lua
reference in the userdata environment. Assignment is a bit more
complex, and it may use more memory (a table per userdata for the
environment), but it clearly describes the relationship between the
objects for garbage collection.