I’ve been reading up on coroutines and i’m really curious about seeing if its possible to make a coroutine stop after each line of code in the function it’s controlling. What is the internal mechanism used to make a coroutine yield? I’m thinking that if you could make a coroutine for each line in a function you read in, then you could stop thru each line if each coroutine were stored in a table sequentially and you just step thru them one by one. make sense?
for a function like this:
function printNotes( tbl )
print( "printNotes in: ", printTableToStr( tbl ) )
local str = ""
for _,v in ipairs( tbl ) do
str = str..pitches[math.fmod(math.abs(v-21),12)]..","
end
print( "printNotes out:", str )
return str
end
you’d have to turn each line into a coroutine and store the coroutine in a table. if you kept a counter that was triggered by a button of which line you were on, you could do something like this:
counter = 0
button.onTouch = function()
coroutine.resume(crs[counter])
counter = counter + 1
end
i’m not sure how you would convert each line into it’s own coroutine, esp. when it comes to for() loops, tho.