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...
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.
declarations for global variables
for-loop variables are read only
floats are printed in decimal with enough digits to be read back correctly.
more levels for constructors
table.create
utf8.offset returns also final position of character
external strings (that use memory not managed by Lua)
new functions luaL_openselectedlibs and luaL_makeseed
major garbage collections done incrementally
more compact arrays (large arrays use about 60% less memory)
lua.c loads 'readline' dynamically
static (fixed) binaries (when loading a binary chunk in memory, Lua can reuse its original memory in some of the internal structures)
dump and undump reuse all strings
auxiliary buffer reuses buffer when it creates final string
source: https://www.lua.org/manual/5.5/readme.html#changes