lua-users home
lua-l archive

RE: When does __index metamethod get called?

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


__newindex is used for any write to he table.
__index is a getter, __newindex is the setter.
Doub.

De : lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] De la part de Chris
Envoyé : 16 mars 2006 18:20
À : Lua list
Objet : When does __index metamethod get called?

Example:

tbl = {}
setmetatable(tbl, {__index = function(t,k) print("test") end})
tbl[1] = 1
tbl[2] = 2

Prints nothing... ??

Also, is there any metamethod that you can hook to know when a value is being set? I know there is __newindex but that only appears to be called for new values being inserted into the table. I want to hook both cases of new values and also setting existing values.

--
// Chris

AltStyle によって変換されたページ (->オリジナル) /