lua-users home
lua-l archive

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


I forgot to mention I'm using Lua 5.1. I did see a metamethod __len but I think it's only called if the arg is not a table?


On Mon, Dec 3, 2012 at 8:49 PM, Coda Highland <chighland@gmail.com> wrote:
On Mon, Dec 3, 2012 at 5:44 PM, Marc Lepage <mlepage@antimeta.com> 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.
>
> But I can't do this:
>
> for i = 1, #t do
>     local child = t[i]
> end
>
> Because #t still returns 0.
>
> Comments and feedback welcome.

Isn't there a metamethod for length in Lua 5.2?

/s/ Adam