lua-users home
lua-l archive

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


On Tue, Oct 29, 2019 at 7:08 AM Pavel <temp213@gorodok.net> wrote:
> my question is not about REPL, where each line has a 'return' prepended if
> interpretation is failed.

On Tue, Oct 29, 2019 at 11:24 AM Pavel <temp213@gorodok.net> wrote:
> v wrote
> > Try running `string.char(65)` in REPL. This is a valid function call
> > without return, but result is still printed.
>
> sure, because REPL just prints what is left on stack and would try add
> 'return' if line is not loaded properly. (in case of '1+2')

You have it backwards. See "loadline" in lua.c:
https://www.lua.org/source/5.3/lua.c.html#loadline. First "return " is
added to the beginning of the line ("addreturn"), then the line is
compiled on its own ("multiline"). So a function call, which can be
parsed as an expression or a statement, will be treated as an
expression and its return values will be printed.

— Gabriel