[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How do you return multiple values?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 4 Nov 2009 18:09:01 -0200
> How do you return multiple values from a function that pcalls a function
> that returns an unknown number of values possibly including nil in a
> manner that doesn't involve undefined behaviour?
>
> [...]
>
> function b()
> local status, r = pcall(function() return { a() } end)
> if not r then error("nicely handled error!") end
> return unpack(r)
> end
>
> [...]
function pack (...)
return { n = select("#", ...); ... }
end
function b()
local r = pack(pcall(function() return { a() } end))
if not r[1] then error("nicely handled error!") end
return unpack(r, 2, r.n)
end
?
-- Roberto