Re: Inconsistent Multiline String Handling in Lua REPL (Direct Input vs. History Recall)

"'TopchetoEU' via lua-l" <[email protected]> Sun, 02 Aug 2026 21:32:56 +0000
Newsgroups gmane.comp.lang.lua.general
Message-ID <1eHhvdwGzV8FnCcQtsHcBnAl9fZKLx-tmp-jLB50e2eO9g7vfQ6uPW1WhcwtXH_EZGzx9ifAtzNcMeXSi923hVHfu9468JXdlmbTg5MPTno=@topcheto.eu>
Wouldn't trying to parse multiline inputs as expressions be a more useful b=
ehavior here? Under the current circumstances a perfectly valid expression =
would be "promoted" to a statement, provided it is multiline. So for this i=
nput:

    > function some_func(...) --[[ do something useful... ]] return ... end
    > some_func(1, 2,
    >> 3, 4)

You would never see the return values of `some_func`, because it was promot=
ed to a statement.

Also, you have this weirdness where a perfectly valid expression is not a v=
alid statement, so lua complains. However, I can't think of a valid reason =
to break up non-call expressions, other than tables (of course writting out=
 a plain table in the REPL seems rather misguided...)


On Thursday, July 30th, 2026 at 7:20 PM, Roberto Ierusalimschy <roberto@inf=
.puc-rio.br> wrote:

> > In Lua REPL, direct input of multiline strings fails with a syntax erro=
r,
> > while recalling the same input via history navigation (up arrow) execut=
es
> > 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.
>=20
> This is documented behavior:
>=20
>     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.
>=20
> 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,
>=20
>   > a =3D 10 +
>   >> 20
>=20
> works, but
>=20
>   > 10 +
>   >> 20
>=20
> doesn't.
>=20
> 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.
>=20
> -- Roberto
>=20
> --
> 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/202=
60730161948.GA11249%40arraial.inf.puc-rio.br.
>=20

--=20
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 e=
mail to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/1eHhv=
dwGzV8FnCcQtsHcBnAl9fZKLx-tmp-jLB50e2eO9g7vfQ6uPW1WhcwtXH_EZGzx9ifAtzNcMeXS=
i923hVHfu9468JXdlmbTg5MPTno%3D%40topcheto.eu.