lua-users home
lua-l archive

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


On Fri, 5 Nov 2004 17:23:08 -0800, Nick Trout
<nick@rockstarvancouver.com> wrote:
> Why do we need a length operator?

Agreed. I think that the best way to implement this would be a
standard function that would delegate to metamethods. Something like
(probably reimplemented in C):

function sizeof(t)
    local tmt = getmetatable(t)
    return ((tmt and tmt.__sizeof) or table.getn)(t)
end

This doesn't do a thing to decrease readability, is a cinch to
override for special tables, works for userdata, doesn't pollute the
syntax, and the semantics will work equally well for some other
"standard" table operation we think of six months down the line
without having to introduce yet another operator.

Ben