Repro:
for k,v in ipairs,{} do end
Repro:
for k,v in ipairs,{} do end
This is not an issue, that’s how generic for loops work.
for vars in iterator, table, index do
end
Since you used ipairs as your iterator, it was called indefinitely because it returned another iterator function.
Use next
instead if you’re going to use this format.
for i, v in next, table do
end
(ipairs returns next, table, nil)
There is a section in the Lua manual with documentation on how iterators work: Lua 5.1 Reference Manual
It usually only comes up when implementing a new iterator.
Effectively, your code is syntax sugar for the following:
local f, s, var = ipairs, {}, nil -- N.B.
while true do
var = f(s, var) -- f(s, var) == ipairs({}, nil) == next, {}, nil ; var is set to next
if var == nil then break end -- never taken, because f always returns next which is not nil
-- loop body goes here
end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.