Skip to content

Instantly share code, notes, and snippets.

@rlorca
Created June 26, 2012 16:07
Show Gist options
  • Save rlorca/2996732 to your computer and use it in GitHub Desktop.
Save rlorca/2996732 to your computer and use it in GitHub Desktop.
Coroutines in Lua
function foo ()
return coroutine.yield("ho ho ho")
end
co = coroutine.create(function (a)
return foo() * a
end)
print("intermediate result", coroutine.resume(co, 3))
print("final result", coroutine.resume(co, 7))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment