lua-users home
lua-l archive

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


2017-06-26 3:26 GMT+02:00 Italo Maia <italo.maia@gmail.com>:
> I always thought lua approach on arrays was quite clever. I miss the fact
> that "non-arrays" cannot be counted with #, but beside that, all is fine.

Oh, but they can.

tbl = setmetatable({a="a",b="b"},{
  __len = function(tbl)
    local n=0
    for k in pairs(tbl) do n=n+1 end
    return n
  end})