lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Just put em into a table:

> function r5() return 1, 2, 3, 4, 5 end
> re = {r5()}
> for k, v in ipairs(re) do print(k, v) end
1	1
2	2
3	3
4	4
5	5


On Mon, Dec 20, 2010 at 2:23 PM, starwing <weasley.wx@gmail.com> wrote:
> 2010/12/20 Michal Kottman <k0mpjut0r@gmail.com>:
>> On Mon, 2010-12-20 at 20:48 +0800, starwing wrote:
>>> i.e. i want to do that:
>>>
>>> ??? = coroutine.resume(...)
>>> if ???[1] then
>>>      --- do something with ???[1...]
>>> else
>>>      --- do something with ???[1...]
>>> end
>>>
>>> but I don't want to use table, I just wonder it's possible to
>>> implement it just operate the multi-values itself.
>>
>> Create locals from them. For example, if your thread yields 3 values:
>>
>> local ok, val1, val2, val3 = coroutine.resume(...)
>> if ok then
>>  -- do something with 'val1', 'val2', 'val3'
>> else
>>  -- 'val1' is the error message, process it
>> end
>>
>>
>>
>>
> but what if I don't know the amount of multi return values?
>
>