lua-users home
lua-l archive

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


Alex Davies <alex.mania <at> iinet.net.au> writes:

> 
> I had the same problem when I was just starting out, as it isn't obvious in 
> the documentation but Lua allows a table to be associated with a userdata 
> and marks it appropriately.  So all circularly references are handled 
> correctly, something that's hard to do via the registry.
> 
> Quick example:
> lua_newuserdata(L, 0);
> lua_newtable(L);
> lua_pushvalue(L, -1);
> lua_setfenv(L, -3);

Thanks for the info Alex!  It's true that this is better than putting
stuff in the registry.  I would still prefer to avoid having to
construct this per-userdata table at all, but this at least makes it a
little more tolerable.

Josh