lua-users home
lua-l archive

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


i haven't used metatables so far but the basics are to check, on assignment,
wether the index is a string and wether the value is nil (delete index) or
not (new index) and based on that, update a counter in the table

Lua 5.0.2 don't call __newindex when the value is nil (don't ask me why).

[luacode]

t = setmetatable({}, {__newindex=function(self,k,v) print(k,v) rawset(self,k,v) end})
t.a=5
> a	5
t.b=6
> b	6
t.a=nil
t.c=7
> c	7

[/luacode]

--rb