lua-users home
lua-l archive

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


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