Re: Inconsistent Multiline String Handling in Lua REPL (Direct Input vs. History Recall)
Roberto Ierusalimschy <[email protected]> Thu, 30 Jul 2026 13:19:48 -0300
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <[email protected]> |
> In Lua REPL, direct input of multiline strings fails with a syntax error,
> while recalling the same input via history navigation (up arrow) executes
> correctly. This behavior is observed starting from Lua 5.3.x. In Lua 5.2.4,
> history navigation as a feature did not exist, so the issue cannot be
> verified in earlier versions.
This is documented behavior:
In interactive mode, Lua repeatedly prompts and waits for a line.
After reading a line, Lua first tries to interpret the line as an
expression. If it succeeds, it prints its value. Otherwise, it
interprets the line as a chunk. If you write an incomplete chunk,
the interpreter waits for its completion by issuing a different
prompt.
Note the "tries to interpret THE LINE as an expression" and "If you
write an incomplete CHUNK": Lua only accepts entire chunks as multiline
input; it does not accept expressions. So,
> a = 10 +
>> 20
works, but
> 10 +
>> 20
doesn't.
The idiosyncrasy is the fact that it accepts when it comes through
history navigation; it is because then the input, although having
multiple lines, is not really a "multiline" input (e.g., no different
prompt); it goes all in one step.
-- Roberto
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/20260730161948.GA11249%40arraial.inf.puc-rio.br.