You read the title and you’re probably confused so I’ll explain my confusion with the engine…
I understand that there’s a recursion stack overflow limit set in place, however I do not understand why I’m reaching the limit when the multilevel table that I generated with another recursive loop is perfectly within the bounds of the stack limit?
The table will contain 5000 levels of nests right, because I end the generation at that point. Now, when I iterate through those levels with another recursive loop which SHOULD stop when it reaches the bottom and yields when it can’t find the last element past the index… It somehow keeps on going without printing anything all the way to its recursion limit… WHY? It works fine when I generate 4000 levels, but at 5000 it just breaks even though the first recursive loop could handle more stacks than that…
Try it with a 16K stack and you can perfectly generate all those levels but it can’t iterate through them…
tabl = {}
-- Iteratating through generated multilevel nested table.
local function iter(t)
t = t[1]
print(t)
--[[
This doesn't error "nil" after reaching bottom of the nest?
It's as if the stack doesn't understand to stop at nil and keeps going.
]]
return iter(t)
end
-- Generating a nested table.
local function nest(tab, stack)
tab[1] = {
[1] = {},
[2] = "THIS IS SOME DATA",
}
stack += 1
-- Breaking stack at 5K.
if stack == 5000 then
return
end
return nest(tab[1], stack)
end
nest(tabl, 0)
iter(tabl)