lua-users home
lua-l archive

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



I like the 'why?' Winnie-the-Pooh question.  Especially this one.

Jettisoning getn completely is okay, as far as 'ipairs' et.al. work as they should. Which, brings us back to the holes / not holes issue, since also ipairs may stop at holes (is that defined, by the way).

-ak

6.11.2004 kello 03:46, Ben Sunshine-Hill kirjoitti:

 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