I can usually work out how to code the iterators I want in LUA.
But recursive iterators have me beat.
For example, here's a Python recursive iterator that returns all items in a nested list:
def items(x):
if isinstance(x,(list,tuple)):
for y in x:
for z in items(y): yield z
else:
yield x
for x in items([10,20,[30,[40,50],60],[70,80]]): print(x)
This prints
10
20
30
40
50
60
70
80
But I can't get it going in Lua. I think it is because I don't know how to carry around the state of the recursive traversal from one step in the iteration to the next.
Suggestions?