[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: custom "mark" function for userdata?
- From: "Alex Davies" <alex.mania@...>
- Date: Mon, 10 Aug 2009 14:42:17 +0800
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);
After this script the table at the top of the stack is associated with the
userdata below it (and can be retrieved by lua_getfenv).
Hope this helps :)
- Alex