Skip to content

Lua 5.5 incompatibility with the variable in the for loop now being constant #16

@davebellows

Description

@davebellows

I just updated to Lua 5.5 and ran into multiple instances of the same problem where the loop variable of a FOR statement is modified. This isn't allowed in Lua 5.5 as the loop variable in the FOR loop is now a constant. Here is an example from around line 251:

for y = 0, 127 * 256, 256 do
   for x = y, y + 127 do
      x = AND_of_two_bytes[x] * 2
      AND_of_two_bytes[idx] = x
      AND_of_two_bytes[idx + 1] = x
      AND_of_two_bytes[idx + 256] = x
      AND_of_two_bytes[idx + 257] = x + 1
      idx = idx + 2
   end
   idx = idx + 256
end

So the third line "x = AND_of_two_bytes[x] * 2" is the problem. The error message reads:

attempt to assign to const variable 'x'

This same problem happens again many more times with lines in the form of:

pos = pos + 4 -- or + 8

There might be more such examples but that's what I found.

I'm not much of a programmer at all but use this module extensively in a project and have no idea how to fix it myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions