lua-users home
lua-l archive

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

On Thu, Feb 19, 2009 at 4:32 AM, Vaughan McAlley <> wrote:
2009/2/19 Etan Reisner <>:
> Personally I tend to avoid using table.insert in favor of
>    tab[#tab + 1] = item
> or keeping an explicit counter, but that probably doesn't matter much
> except in tight loops.

It took me a while to work out why this is popular (apart from
featuring heavily in Programming in Lua). It's because this method
allows access to metamethods, while table.insert doesn't. Am I right?


Don't forget overriding the __len metamethod is not supported in tables yet, so unless 'tab' could also be a full userdata #tab will always mean the same thing. I think tables are planned to support custom __len metamethods in the future, thjough.