[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 'table' as fallback for tables
- From: Hisham <h@...>
- Date: Tue, 28 Jun 2016 15:45:08 -0300
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
- References:
- 'table' as fallback for tables, Dirk Laurie
- Re: 'table' as fallback for tables, Philipp Janda
- Re: 'table' as fallback for tables, Roberto Ierusalimschy
- Re: 'table' as fallback for tables, Philipp Janda
- Re: 'table' as fallback for tables, Tim Hill
- Re: 'table' as fallback for tables, Philipp Janda
- Re: 'table' as fallback for tables, Roberto Ierusalimschy
- Re: 'table' as fallback for tables, Philipp Janda
- Re: 'table' as fallback for tables, Coda Highland
- Re: 'table' as fallback for tables, Jay
- Re: 'table' as fallback for tables, Tim Hill
- Re: 'table' as fallback for tables, Dirk Laurie
- Re: 'table' as fallback for tables, steve donovan