[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Little fun with vararg
- From: Eduardo Ochs <eduardoochs@...>
- Date: Sun, 3 Aug 2014 14:35:13 -0300
The outer parentheses in
return (table.unpack(tk) )
truncate the results of table.unpack(tk) to a single result.
On Sun, Aug 3, 2014 at 2:22 PM, jseb <gmane2013@finiderire.com> wrote:
> Hello, it's probably a dumb question, but when i try to print the
> returned table.unpack, i get only the first key.
>
> I know that «table.unpack» will do: return list[i], list[i+1], ···,
> list[j].
>
> So i should get the values by doing :
> local a,b,c,… = get_keys(t)
>
> But all variables after a are nil.
>
> function get_keys(t)
> local key=nil
> local tk={}
> repeat
> key = next(t,key)
> if tk~=nil then tk[#tk+1]=key end
> until key==nil
>
> print(table.unpack(tk))
> return (table.unpack(tk) )
> end
>
> local t={nom="marcel",age=42,sexe="oui"}
> print (get_keys(t))
>
>
> $ ./get_keys.lua
> nom age sexe
> nom nil nil
>
>
> Thank you.
>
>
>