Missing global warning in lua interactive mode

61 views
Skip to first unread message

Jure Bagić

unread,
Feb 7, 2026, 12:46:54 AM (4 days ago) Feb 7
to lua-l
When running lua standalone interactively the usual warning for the local
statement works properly in the latest release but not for the global
statement/declaration.

Or such warning is not there on purpose?

(lua.c:621:checklocal)

--
Jure
signature.asc

Jure Bagić

unread,
Feb 7, 2026, 1:22:47 AM (4 days ago) Feb 7
to lua-l
P.S: I do realize globals survive across multiple lines. I just think it would
be a good idea for user to get a hint that his global definition has no usual
implications on the following lines when in the interactive mode outside of a
block.

--
Jure
signature.asc

Roberto Ierusalimschy

unread,
Feb 7, 2026, 12:47:45 PM (4 days ago) Feb 7
to lu...@googlegroups.com
It is quite common that someone sees a piece of code, enters it line by
line in the REPL, and then it doesn't work as expected because there is
some local declaration in the code.

The the "local" warning was added specifically because of that common
scenario, not as some generic hint. The fact that "global" does not
survive accross lines cannot change the meaning of some piece of code
(or can it?), so it is not worth a warning.

-- Roberto

Jure Bagić

unread,
Feb 7, 2026, 10:58:28 PM (3 days ago) Feb 7
to lu...@googlegroups.com
I guess what to me looked wrong was the 'const' attribute:
> global <const> A = 1;
> A = 2; assert(A == 2);

But again, as you pointed out, the meaning of the following line is not changed
and nobody would write this anyway.

-- Jure
signature.asc
Reply all
Reply to author
Forward
0 new messages