[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: length operator [was: table insertion]
- From: Asko Kauppi <asko.kauppi@...>
- Date: Sat, 6 Nov 2004 14:43:57 +0200
I like the 'why?' Winnie-the-Pooh question. Especially this one.
Jettisoning getn completely is okay, as far as 'ipairs' et.al. work as
Which, brings us back to the holes / not holes issue, since also ipairs
may stop at holes (is that defined, by the way).
6.11.2004 kello 03:46, Ben Sunshine-Hill kirjoitti:
On Fri, 5 Nov 2004 17:23:08 -0800, Nick Trout
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):
local tmt = getmetatable(t)
return ((tmt and tmt.__sizeof) or table.getn)(t)
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.