[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Little fun with vararg
- From: jseb <gmane2013@...>
- Date: Sun, 3 Aug 2014 19:22:32 +0200
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.