Lua 5.5.0 - "global" as a identifier

59 views
Skip to first unread message

João Pedro Gusatti

unread,
Jan 17, 2026, 9:02:30 AM (4 days ago) Jan 17
to lua-l
Hello,
I was doing some tests in the new Lua version 5.5.0 and found a possible inconsistency between the Reference Manual and the actual behavior of the interpreter.
In the Lua 5.5 Reference Manual, section 3.1 Lexical Conventions, it states:

"The following keywords are reserved and cannot be used as names:"

and the keyword global is included. However, it is possible to declare variables with the name global:

global = 1
print(global) --> 1

The interpreter treats global as a normal variable name in this context, even though the manual states it is reserved.

However, when used at the beginning of a statement, it behaves as a keyword:

global var = 2
global *
print(var) --> 2

Is this intentional behavior for backwards compatibility?
If so, I would suggest adding some clarification in the Reference Manual.

Thanks in advance,

João Pedro Gusatti

Luther Thompson

unread,
Jan 17, 2026, 10:24:17 AM (4 days ago) Jan 17
to lu...@googlegroups.com
On 1/17/26 09:00, João Pedro Gusatti wrote:
> global = 1
> print(global) --> 1
>
> The interpreter treats global as a normal variable name in this
> context, even though the manual states it is reserved.

This is a backward compatibility feature. Before compiling, I went to
luaconf.h and commented out LUA_COMPAT_GLOBAL, so for me, `global = 1`
does throw an error.

Luther

Reply all
Reply to author
Forward
0 new messages