lua-users home
lua-l archive

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

I think this sort of thing has an official name... in Ruby the last statement -- what it evaluates to -- gets returned if it isn't explicitly preceded with a 'return '.  In Lua you cannot have expressions in the middle of nowhere.  You can have s2 = a * b, but you can't have a * b.  It might look a tad confusing to have s2 = a * b and expect that value to be returned if you're reviewing the code...

Also, how many values would be returned?  Would you look at the statements within the calling function to determine how many of the last-computed values in the called function should be returned?

Might be a little confusing ;>  I understand you probably want this for convenience as it makes the code more concise, but I would suggest trying to get used to explicit return statements...  I'm not sure upstream Lua would be in favor of this, but best of luck \o/

On Tue, Nov 19, 2013 at 1:26 PM, Stéphane Aulery <> wrote:
>De: Pierre-Yves Gérardy <>
>Envoyé: Tue, 19 Nov 2013 10:55:07 +0100 (CET)
> On Mon, Nov 18, 2013 at 10:55 PM, Stéphane Aulery <> wrote:
> > I do not know if this is doable, but I would find it convenient to name
> > the return values of functions to facilitate code maintenance.
> Something like this?
>     function add(a, b) returning c
>         c = a + b
>     end

Yes, or like that :

    function (s1, s2)add(a, b)
        s1 = a + b
        s2 = a * b

    sum1, sum2 = add(3, 8)
    sum1, sum2 = (s1, s2)add(3, 8)
    sum2 = (s2)add(3, 8)

Stéphane Aulery