[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Tables, Metatables, Children, and Length
- From: spir <denis.spir@...>
- Date: Tue, 04 Dec 2012 19:41:48 +0100
On 04/12/2012 02:44, Marc Lepage wrote:
Hi, I have a table which has a metatable. I want to add children (other
tables) to the metatable, not to the table directly.
If I do so, I can get at them by t[1], t[2], t[3] and so on.
This means you customised __index, right?
But I can't do this:
for i = 1, #t do
local child = t[i]
end
Because #t still returns 0.
If so (unless i'm wrong), why don't you just customise __newindex, too, to
maintain an up-to-date item count ('n' is often used in Lua). Then
for i = 1, t.n do ... end
I would find this coherent.
Denis