lua-users home
lua-l archive

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


Can you link a discussion behind this design decision?

Am 2010 11 18 13:11 schrieb "Pierre-Yves Gérardy" <pygy79@gmail.com>:
> On Thu, Nov 18, 2010 at 12:14, starwing <weasley.wx@gmail.com> wrote:
>>
>> hi all...
>> I'm confused about the multi return value of Lua.
>> how can I insert the multi return value from a function to a middle of a table?
>
> You can do it to some extent in a table constructor literal:
>
> a=function() return 1,2,3 end
>
> b={5,6,a()} --> b is now {5,6,1,2,3}
>
> However, if the returned values are not inserted at the end of the
> table, only the first returned value will be assigned.
>
> c={5,6,a(),9} --> c is now {5,6,1,9}
>
> The same rules apply to varargs:
>
> z=function(...) return {55,...} end
> z(1,2,3) --> { 55, 1, 2, 3 }
>
> but
> w=function(...) return {...,18} end
> w(1,2,3) --> { 1, 18 }
>
> Regards,
> -- Pierre-Yves
>