lua-users home
lua-l archive

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


> 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).

-- Roberto