lua-users home
lua-l archive

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


On 28 June 2016 at 03:29, steve donovan <steve.j.donovan@gmail.com> wrote:
> On Tue, Jun 28, 2016 at 8:07 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> 1. If the __index metamethod exists, use it.
>> 2. If not, use tbl["#"] as the length.
>> 3. If that is nil or false, revert to the built-in algorithm.
>
> Assume that '__len' is meant, not '__index'
>
> Why not simply leave out (2)?  Imagine having to explain how #t works
> in a future manual.
>
> However, I'm all for table.pack() returning a table which has a
> metatable with __len = self.n, and table.unpack() respecting this.

To be honest, this thread made me realize that I always assumed that
table.unpack() was symmetrical to table.pack() (that is, that it
respected .n). This means I most likely have buggy production code out
there that I need to double-check. Shame on me!

-- Hisham