News for hackers. Stuff that matters.
Re:Lua 5.5.0 Released by cturtle on Monday December 22, 2025 @11:36AM (#46355610)
One of the new features I found interesting, declarations for global variables, is buried in the reference manual. Here's a link to the section that discusses it: https://www.lua.org/manual/5.5/manual.html#2.2
Re:Lua 5.5.0 Released by buybackoff on Tuesday December 23, 2025 @04:03PM (#46369432)
Hyperlinks must be underlined at least in a paragraph text. I was looking for a link like that for some time without any clue and then just randomly hovered over a piece of text that changed color.

I'm a little sad they go the way similar to Python at the first glance. For me, the way TypeScipt took initially and ECMAScript picked up eventially, with explicit export but lexical scoping otherwise, seems like the best "don't make me think" way. Why I should care about global/local inside a module? What benefits does it give vs lexical scoping with shaddowing allowed?

Re:Lua 5.5.0 Released by rhelz on Tuesday December 23, 2025 @06:36PM (#46370798)
Why did you find this interesting?
Re:Lua 5.5.0 Released by embedding-shape on Tuesday December 23, 2025 @06:42PM (#46370839)
For me it's interesting because global variable declarations haven't been needed before, so why now? Also, I'm not sure `global` was reserved before, but now it seems to be.
Re:Lua 5.5.0 Released by TheCycoONE on Wednesday December 24, 2025 @11:31AM (#46376948)
lua does not preserve compatibility between minor versions. As such they don't need to reserve words for future use.
Re:Lua 5.5.0 Released by mjmas on Thursday December 25, 2025 @09:53AM (#46384751)
The point now is so that if you use a `global` statement in your code, Lua will now error on misspellings of local variables when compiling, rather than defaulting to treat them as globals.
Re:Lua 5.5.0 Released by kevin_thibedeau on Tuesday December 23, 2025 @09:42PM (#46371874)
It indicates paving the path for local scoping in a future release where Lua 5 code is upgraded with global declarations to keep it working.
Re:Lua 5.5.0 Released by NuclearPM on Tuesday December 23, 2025 @10:23PM (#46372080)
We have had local scoping for decades.
Re:Lua 5.5.0 Released by HellsMaddy on Tuesday December 23, 2025 @08:01PM (#46371298)
Global-by-default scoping was one of Lua's largest mistakes. I wish they'd fix it, but of course it would break backwards compat.
Re:Lua 5.5.0 Released by drcxd on Wednesday December 24, 2025 @01:48AM (#46373110)
Strictly speaking, Lua is not global by default. All free names, that is, all names unqualified with `local`, is actually indexed from a table `_ENV`, which is set to `_G`, the global environment. So, all free names are effectively global by default, but you can change this behavior by put this line at the top of your file `local _G = _G; _ENV = {};`. This way, all free names are indexed from this new table, and all access to the global names must explicitly be accessed through `_G`, which is a local variable now. However, I have never seen such practice. Maybe it is just too complicated to accept that all free names are global variables and you have to explicitly make it local.
Re:Lua 5.5.0 Released by Fwirt on Wednesday December 24, 2025 @04:11AM (#46373900)
Thanks to Lua’s great metaprogramming facilities, and the fact that _G is just a table, another workaround is to add a metamethod to _G that throws an error if you try to declare a global. That way you can still declare globals using rawset if you really want them, but it prevents you from declaring them accidentally in a function body.
Re:Lua 5.5.0 Released by kanbankaren on Wednesday December 24, 2025 @01:13PM (#46377822)
yeah. I hate typing `local` for every variable. I would prefer they introduce some syntactic sugar like `let`(to mean local variable) and `const`(to mean local and constant).
Re:Lua 5.5.0 Released by otikik on Wednesday December 24, 2025 @01:34PM (#46377993)
“local” is the same as the “let” that you are describing, isn’t it? Just 2 chars longer.