[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how to store multi return value provisionally?
- From: Michal Kottman <k0mpjut0r@...>
- Date: Mon, 20 Dec 2010 14:41:46 +0100
On Mon, 2010-12-20 at 21:23 +0800, starwing wrote:
> 2010/12/20 Michal Kottman <k0mpjut0r@gmail.com>:
> but what if I don't know the amount of multi return values?
Then you either have to use the table ('th' is the thread, '...' is the
vararg expression):
local ret = {coroutine.resume(th)}
local ok = table.remove(ret, 1) -- returns 1st element and shifts other
if ok then
-- 'ret' contains the return values
-- you can use unpack(ret) to get multi-return values again
else
error(ret[1])
end
Or you can use a helper function:
local function process(ok, ...)
if ok then
-- work with '...' as normal
else
error(...)
end
end
process(coroutine.resume(th))