lua-users home
lua-l archive

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


On Sun, 2011-01-02 at 20:00 -0300, Emmanuel Oga wrote:
> Alternatively you can use the indexes to the real table/array provided
> in the table
> 
>   for k,v in ipairs(t.___array) do print(k, v) end
>   for k,v in pairs(t.___table) do print(k, v) end
> 
> Which I believe is even more ugly than using the iterators above.
> 
> I tried to override __len on the metatable but apparently that does
> not work in lua 5.1 (I read somewhere __len will be overridable for
> tables/strings in 5.2?)

In Lua 5.2, not only __len will work for tables, but also __pairs and
__ipairs are added, making it possible to use your 'arrayTable' with the
standard pairs() and ipairs() functions.