lua-users home
lua-l archive

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

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')

question was why statements like '1+2' are syntax error (opposite to C).

but reimplementing RE[P]L in Lua to fix it is also fine

local str = ""
for s in io.lines("somefile.lua") do
  str = str .. s
  local f, err = load(str)
  if not f then f, err = load("return " .. str) end
  if f then f(); str = "" end 

Sent from: