[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (work1) now available
- From: Alexander Gladysh <agladysh@...>
- Date: Sat, 9 Jan 2010 13:12:38 +0300
On Sat, Jan 9, 2010 at 12:58, steve donovan <steve.j.donovan@gmail.com> wrote:
> On Sat, Jan 9, 2010 at 11:52 AM, Alexander Gladysh <agladysh@gmail.com> wrote:
>> (1) Don't have holes in tables you want to measure with #, that's all.
> Amen. But in general pack() will give you them. I agree, 'n' is a nasty hack.
> We are back in the table-with-holes thread ;)
> I am also excited about the __len metamethod.
A crazy idea: what if table.pack() would set a (pre-defined) metatable
to the tables it creates, with __len metamethod looking at n?
This is rather unusual behavior for Lua API function, but I can't see
much harm (yet), and it looks useful.
Two things would be required though: (1) "official" way access to this
metatable, since people would try to "steal" and reuse it anyway, and
(2) a flag argument for table.pack() to skip metatable setting, for
rare cases when resulting table would be reused for something
incompatible with it...
Alexander.