lua-l archive

• Subject: Re: Return a variable number of values from function
• From: Edgar Toernig <froese@...>
• Date: Mon, 19 Nov 2001 01:25:50 +0100

```Matthias Gall wrote:
>
> I just asked myself whether it's possible to have something like the vararg
> function for function results: a function returns a variable number of
> values. I would be happy about a short code snippet, if this feature is
> supported. I am using LUA 4.0.

Is this short enough? *g*

function pack(...)
return arg
end

Example:

function func1() return end
function func2() return 1,"foo",3 end
function func3() return {} end

x = pack(func1())
foreach(x, print)	--> n=0

x = pack(func2())
foreach(x, print)	--> n=3  =1  ="foo"  =3

x = pack(func3())
foreach(x, print)	--> n=1  =table:xxx

Ciao, ET.

```
{"ft_lang_label":"__label__en","ft_lang_prob":0.5736096,"math_prob":0.97159326,"size":840,"snap":"2019-35-2019-39","text_gpt3_token_len":256,"char_repetition_ratio":0.1375598,"word_repetition_ratio":0.0,"special_character_ratio":0.34166667,"punctuation_ratio":0.1724138,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9690959,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-09-22T02:20:22Z\",\"WARC-Record-ID\":\"<urn:uuid:d6ab36be-a953-4521-a590-7fab06f3fb19>\",\"Content-Length\":\"4227\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e7de8ae9-9c11-4b66-bf11-ec017b80d2bc>\",\"WARC-Concurrent-To\":\"<urn:uuid:9fac37aa-fe7b-48ad-b133-79b7fd44d940>\",\"WARC-IP-Address\":\"88.99.213.221\",\"WARC-Target-URI\":\"http://lua-users.org/lists/lua-l/2001-11/msg00232.html\",\"WARC-Payload-Digest\":\"sha1:QUNRTTNG32JSOVFZ33QENHKIDREA3ZRO\",\"WARC-Block-Digest\":\"sha1:TDVHPXYPUK6466XKYAEINESDMO7F4RX4\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-39/CC-MAIN-2019-39_segments_1568514574765.55_warc_CC-MAIN-20190922012344-20190922034344-00079.warc.gz\"}"}