lua-users home
lua-l archive

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


I agree, #t is enough useful, IMHO, to let it as it is (until someone found a better solution, of course).
Moreover, as said in http://www.lua.org/work/doc/, "tables honor the __len metamethod" in lua 5.2.

But I was wondering if __len and __newindex are enough to easily emulate all four of these options, as you can't detect adding some "holes" in your table.
So here is my question: would it be interesting to add a __delindex or __remindex metamethod called when an existing table index/key is setted to nil?

Not sure it is a really useful/interesting feature (definitively not a request from me, i'm just sharing the idea)...

PS: __del/remindex could also help to prevent removing some keys from a table (some kind of readonly?).

>From HyperHacker:
>
>Or just let #t remain as-is, but have it honour the __len metamethod
>for tables, so that one is free to define it however they like for
>each table. Make it clear in the manual that if your array has holes
>and you don't define __len, then #t has no real meaning. Between
>__len and __newindex, one can emulate all four of these options.