lua-users home
lua-l archive

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

I assume such a weak table would have strong keys (light userdata containing the address of the full userdata) and weak values (full userdata)?

Then, the storage of the full userdata does not prevent its collection, but the entries should not be collected if no other references to the light userdata exist.

On Tue, Feb 12, 2013 at 2:05 PM, Kevin Martin <> wrote:

Unless I'm misunderstanding, isn't the standard way to do this is to maintain a weak table where the keys are lightuserdata with the address of of the full userdata, and the the values are the full userdata itsself.

You can then look the userdata up by address in the table.


On 12 Feb 2013, at 18:57, Marc Lepage wrote:

> Hi, I'm doing more with userdata and am just wondering, is it safe to push the address of a (full) userdata to keep a reference to it? And remove that reference in the userdata's __gc function?
> Basically, I want to store within the C userdata itself, a reference to the Lua object version of it. This is so that even if I pass it through C code (without Lua), I can later get back the Lua version of it, for additional processing.
> Or, is there a better way to turn the address of a (full) userdata, in C, back into its Lua object?