[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.2 - small enhancement for table.unpack
- From: Daurnimator <quae@...>
- Date: Wed, 29 Jun 2011 18:46:36 +1000
On 29 June 2011 17:25, Lorenzo Donati <lorenzodonatibz@interfree.it> wrote:
> Hi all!
>
> I'd like to suggest a small enhancement for table.unpack.
>
> I propose to add this usage case:
>
>
> table.unpack( t, '#' )
>
>
> that would be equivalent to:
>
>
> table.unpack( t, 1, t.n or #t )
>
>
> Rationale:
>
> 1. make table.unpack usage more symmetric with new table.pack, so that a
> table created by pack could be unpacked more easily.
>
> 2. the implementation could be optimized to minimize accesses to t.
>
>
> Thanks for reading.
>
> Cheers.
> -- Lorenzo
>
I'd much rather a change where table.pack just returns a table and length:
function table.pack(...)
return {...},select("#",...)
end
==> this way we dont get the arbitary 'n' key; and unpack is (mostly)
symmetrical:
local t,t_n = table.pack(...)
print(unpack(t,1,t_n))
Daurn.