lua-users home
lua-l archive

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

I just want to chime in that I the original idea of this thread (that is, to
have the Lua interpreter support this) is far superior to any of these "just
add return" methods.

I have tried several methods of intelligently adding return to blocks and it
just sucks. "Script programmers" who are used to Perl and Python and the
like expect to be able to have the following chunks of code return a value
from the equivalent of "eval":

"1 + 4"
"return 1 + 2"
"if a > b then return 0 else return 1 end"
"if b < a then a else b end"

making a "return adder" that handles all of these cases is quite complicated

Just my $.02


> -----Original Message-----
> From:
> []On Behalf Of Roberto
> Ierusalimschy
> Sent: Tuesday, June 26, 2001 12:30 PM
> To: Multiple recipients of list
> Subject: Re: block return semantic
> > It's not possible to wrap any arbitrary block in a return().
> But you can try. With the new lua_loadstring, you can try to compile
> "return "..inputline, and if there is no errors then you call it and
> print the result. Otherwise, you call lua_dostring (without the return).
>   "It is an expression if it looks like an expression" ;-)
>     while 1 do
>       local line = read()
>       local f = call(loadstring, {"return "..line}, "x", nil)
>       if f then print(f())
>       else dostring(line)
>       end
>     end
> -- Roberto