[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Closure or Userdata?
- From: "Duncan Cross" <duncan.cross@...>
- Date: Sun, 16 Dec 2007 14:43:25 +0000
On Dec 14, 2007 3:34 PM, Eike Decker <firstname.lastname@example.org> wrote:
> The userdata needs only to overload the __newindex and __index metatable and
> store new key/values in a table inside the metatable of the userdata OR (if the
> userdata shouldn't have unique metatables) store the value in a table of the
> registry where the key values are the userdata values and it's a __mode='k'
> table, so it's weak.
There is another solution for this - userdata also has an environment
table, which is not internally used for anything, so you can easily
associate an arbitrary table to each instance of a userdata using
lua_setfenv and lua_getfenv while sharing a single metatable.