lua-users home
lua-l archive

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



On 4-Oct-06, at 4:38 PM, Sam Roberts wrote:

On Wed, Oct 04, 2006 at 03:24:53PM -0500, Rici Lake wrote:
Why not just use an empty table whose __index and __newindex methods
use the userdata? In effect, they could be the same __index and
__newindex metamethods you would use with the userdata.

The following hardly changes your example at all:

(Note: I'm using lightuserdata here, something I would normally never
do, but you don't seem to be attaching a __gc metamethod to your

I'm confused. I thought lightuserdata doesn't have an individual
metatable?


They don't. The lightuserdata is passed to the __index and __newindex methods by being placed in an upvalue. The metatable is actually attached to an ordinary, empty Lua table, which is what is returned by pushobject.

Note: I haven't actually *tried* this code. It probably doesn't work. :)

Other Note: I almost never use lightuserdata; I would normally have created a full userdata and attached a __gc metamethod to it.