lua-users home
lua-l archive

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

On 28/06/16 03:45 PM, Hisham wrote:
On 28 June 2016 at 03:29, steve donovan <> wrote:
On Tue, Jun 28, 2016 at 8:07 AM, Dirk Laurie <> 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

Reminder to always read the docs and/or implementation. I miss the days when ppl would read manuals before trying to dry their dog's hair in a microwave.

(OT: Is there any way to lock a system until the user reads the manual?)

Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.