lua-users home
lua-l archive

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


Thank you all. I had misunderstood the use of __index.
 
Greetings
Ignacio
 
----- Original Message -----
Sent: Tuesday, December 30, 2003 8:46 PM
Subject: Re: __index method not being called??

Lua calls __index only when you're trying to read from a field. When you're trying to write to a field (the case in your script) Lua calls __newindex instead. __index=get, __newindex=set. Please check the manual for more details (including Lua code for the field read and field write behavior.
 
For your proxy tables you'll be better off storing pointers to the structs in userdata, setting the __index metamethod to a C function that retrieves the pointer and returns the valueof the correct member and __newindex to a C function that retrieves the pointer and writes to the correct struct member. You can even use the __gc metamethod to free the struct.
 
--
Fabio