Skip to content

Instantly share code, notes, and snippets.

@grumpydev
Last active September 23, 2018 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grumpydev/7f5a5595b71b4d140b95e48053e2659a to your computer and use it in GitHub Desktop.
Save grumpydev/7f5a5595b71b4d140b95e48053e2659a to your computer and use it in GitHub Desktop.
-- co-routines in pico8 seem a bit "broken" ?
-- coresume only passes through the extra arguments once, which seems to fit the lua spec and I can live with that
-- but yield return values seem to be ignored? it only ever returns true/false and an error message if it failed?
-- the below code never displays any return values until the coroutine function stops yielding and hits the final return
left=0 right=1 up=2 down=3 fire1=4 fire2=5
function _init()
counter = 0
fn = cocreate(stuff)
fn2 = cocreate(stuff2)
end
function _update60()
if (btnp(fire1)) then
counter+=1
continue,result = coresume(fn,counter)
continue2,result2 = coresume(fn2,counter)
end
end
function _draw()
cls()
? counter,0,0
? continue,0,10
? result,0,20
? continue2,0,30
? result2,0,40
end
function stuff(a)
-- this will yield forever because the parameters are only passed in once
-- which makes sense because the actual function entry point only gets executed
-- once, just wanted to confiem :)
while(a<10) do
yield("foo")
end
return "done"
end
function stuff2(thing)
-- this returns nothing from coresume (other than the normal true/false)
-- until the final return statement
for i=0,10 do
yield("foo"..i)
end
return "done:"..thing
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment