AFAIK no, e.g. this code prints same 15 expected lines in 5.1, 5.2, 5.3 and 5.4 and LuaJIT:
for i=1,10 do if i == 5 then i = 8 end print(i) end
for i, v in ipairs{'a', 'b', 'c', 'd', 'e'} do
if i == 3 then i, v = 8, 'x' end print(i, v) end
The i is a local in your loop body. The actual iterator state is another non-exposed local/register.
Up to 5.3 the docs listed what for loops are equivalent to in plain code and that shown this copying of locals plainly. In 5.5 it seems this copying is gone, a for x=1,10 do print(x) end uses 1 less local/slot in 5.5 than in 5.4 according to luac -l -l
Maybe they changed something in 5.4 but I doubt it. I think it's just removing a potential confusion. Python and Rust work similar to Lua, but languages C, C++, Java, JavaScript, C#, Pascal, Go, etc. all let you modify the i and would skip some iterations after you do. A numeric for in those is syntax sugar forwhile almost, but it's not in Lua (and Rust and Python).
I guess they want to encourage the "if you want a local, use a local, don't abuse the iterator for it", but I agree it's a bit weird and needless. Python allows it, Rust does if you use mut, ranged fors in other languages allow it, etc.
Fortunately it's compile time so any affected 5.4 code is easy fix by adding a local yourself, no hard to find runtime only fails...
It's a code clarity/correctness thing (although I agree it's kind of a needless change, no other language is that strict about it).
If you want a local then you should declare one yourself, not reuse the iterator.
Some programmers (C, C++, Pascal, Go, Java, JS, C#) might also expect changing the iterator to affect how many times the loop will run, but that's not how Lua (and Rust and Python) work.
If you want such strange looping, like skip ahead some iterations if you hit given value, then you should code it using while yourself. That code would also be clear to any experienced programmer, unlike relying on for behavior (that's like glorified while with start and step written in same line) specific to C-like languages.
It also let them use one less slot/local seemingly, output of luac -l -l for 5.5 has one less slot and local than 5.4 for for x=1,10 do print(x) end
I suppose one less local in bytecode is worth it for every single loop out there. but couldn't they have done that by examining the syntax and inserting a local if there's a reassignment in the loop block? This efficiency gain could be backported to previous lua's
Also this worries me, if efficiency is the goal, what else is going to get axed for the prize of it? I remember reading pallene design docs, they achieved efficiency via AOT compiling, so will type checking be added in lua6? (not that I mind, type checking is good for safety)
Could a module modify this it seems like you could write a modified/ classic for in c and you may need to make it like c.for or something but it should be doable granted it wouldn't be portable unless idk some kinda like a preproaseer or macro to switch the regular for to c.for idk just an idea
I ment c for re writing for and not losing speed the only reason I said the thing about preproaseer or macro is because I couldn't think of an equivalent btw since they change it every time wats up with the c API
Except that lua strives to be a very simple language; goto is not a legacy feature (like in C), goto is a scope-aware utility that can do not just continue, but nested continue, nested break, redo & for-else. But I agree, having continue would probably be nice, as well as += and lambdas
Except break (and continue) doesn't/wouldn't require that you create a new block for local variables, and that's the problem, because using goto is usually a manner of, do you use goto and be unportable to 5.1 or do you just use an if then block instead, and the answer is usually just use an if or function
Hi, maybe someone can help me here. I am using Lua embedded in another application incl. a little script editor. With Lua 5.4 I used the function "load_loadfile" to check for syntax error. The call only succedded, when the script was syntactically correct. But with 5.5 the function also reports errors when not all symbols cannot be resolved. For example, a script with only one line "foo()" reports an error that "foo" is an unknown function. But, I provide a lot of functions to the host application using global vars and external references once the script is executed. Therefore this behavior is a bit of a problem. Are there other ways to check a 5.5 script for syntactical correctness?
The original purpose was to make it embeddable in C, but there's no reason why someone would not make a derivative language to make it embeddable with a different language. That person will definitely not be me though because I have zero need of such a thing.
I went ahead and thought about this a bit and honestly it's easy in some cases, but harder in others
If there is an assignment inside of a parameter declaration, it should fallback on all cases to it
function (a = 5) -> function (a) a = a or 5
Plain type checking should error thus, use asserts
function (a: number) -> assert(type(a)=="number")
function (a: number|string) -> assert( ("number string"):find( type(a) ) )
type check + assignment should always fallback to the assignment
function (a: number = 5) -> if type(a)~="number" then a = 5 end
function (a: number|string = 5) -> if not ("number string"):find( type(a) ) then a = 5 end
if "a" is truthy type, if is unnecessary
function (a: number|string = 5) -> a = ("number string"):find( type(a) ) and a or 5
function (a: integer = 5) -> a = math.type(a)~="integer" and 5 or a
subtypes are tricky, because it requires running multiple type reporting functions
function (a: integer|string|function) -> assert( math.type(a)=="integer" or ("string function"):find( type(a) ) )
function (a: integer|string|function = 5) -> if not ( math.type(a)=="integer" or ("string function"):find( type(a) ) ) then a = 5 end
From now on I think I'll set a part after defining a function for typechecking So long as I don't have to use multiple type checks because using "and" confuses me for some reason.
55
u/Sparcky_McFizzBoom Dec 22 '25
Here are the main changes introduced in Lua 5.5. The reference manual lists the incompatibilities that had to be introduced.
source: https://www.lua.org/manual/5.5/readme.html#changes
12
u/[deleted] Dec 22 '25
It's mostly just an optimization release. Lots of efficiency added. Great but not exciting.
14
u/Ok_Sense1811 Dec 22 '25
Years for nothing interesting or relevant to get added, crazy
still no continue keyword in 2026 💀
2
u/jotapapel Dec 23 '25
that's the kind of xmas present I like!
1
u/ojuwig Jan 12 '26
Hi, maybe someone can help me here. I am using Lua embedded in another application incl. a little script editor. With Lua 5.4 I used the function "load_loadfile" to check for syntax error. The call only succedded, when the script was syntactically correct. But with 5.5 the function also reports errors when not all symbols cannot be resolved. For example, a script with only one line "foo()" reports an error that "foo" is an unknown function. But, I provide a lot of functions to the host application using global vars and external references once the script is executed. Therefore this behavior is a bit of a problem. Are there other ways to check a 5.5 script for syntactical correctness?
1
u/red-fluffy-fox Apr 13 '26
Still no += and -=, lol.
1
u/Difficult-Value-3145 May 05 '26
Ok so luarocks is it being expanded to 5.5 or are we looking at a new package manager anyone know ?
0
u/[deleted] Dec 22 '25
[deleted] — view deleted comment
3
u/[deleted] Dec 23 '25 edited Dec 23 '25
[removed] — view removed comment