lua-users home
lua-l archive

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


> 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