I wanted, but although it runs in Lua, tail calls apparently
block the ESP8266 firmware. Possibly something might be done
by setting up a table of co-routines, and calling each of them
in turn. I'll keep tinkering.
#!/usr/bin/lua
idx = nil
function state_a()
print("State A")
return state_b()
end
function counter()
local n = 0
return function()
n = (n % 16384) + 1
return n
end
end
function state_b()
print("State B")
if idx == nil
then
idx = counter()
end
n = idx()
print(n)
if n < 64
then
return state_b()
else
idx = nil
return state_c()
end
end
function state_c()
print("State C")
return state_a()
end
state_a()
Will