for t, tree in pairs(tab) do .... table.remove(tab, t)
you are sure that it works? you are in a for loop and changes the table which is looped through. the next element would be skipped because the table indices has been moved.
Thanks for the hint, you're right. I guess that's why I used "tab[t] = nil" in the first place! I've just played around on my local Lua installation. Doing it recursively seems to work:
tab = {43, 12, 23, 34, 45, 91, 7, 13, 4}
f = function(tab, start)
for i = start, #tab do
if tab[i] and tab[i] % 2 == 0 then
table.remove(tab, i)
if f(tab, i) then
return true
end
end
end
return true
end
f(tab, 1)
Calling that function will remove all even numbers from the table. If an entry has been removed, the function will be called again, starting at the last entry (which now has a new value). When the end of the table has been reached, the function will return true, which will cause the instance of the function that called it to finish as well. So there hardly is any overhead except for the entries that have been removed. Do you see anything wrong with that logic?
That will have to work
I know, I didn't mean to push you with my thoughts.
No problem, I was just explaining why I can't update…