[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: 'table' as fallback for tables
- From: "Soni L." <fakedme@...>
- Date: Sat, 25 Jun 2016 15:37:11 -0300
On 25/06/16 03:34 PM, Roberto Ierusalimschy wrote:
As I've mentioned elsewhere I'm not a big fan of the `table.pack()`
function, but one nice thing about it is that we now have an
official way to represent sparse tables (with that extra `n` field
that `table.pack()` sets). Strange thing is that `table.unpack()`
*does not* honor that `n` field although those two functions appear
to be inverses of each other.
Unlike table.pack, which creates a new table (and therefore has
complete control over it), table.unpack works with other-people's
tables. Therefore, it seems better not to assume particular policies on
how those tables work. If you want to unpack a "table.pack" table, just
call table.unpack(t, 1, t.n).
Why doesn't table.pack set a default metatable that uses self.n for __len?
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.