Created
May 22, 2017 08:41
-
-
Save zwh8800/c111c74f68c0eea7e95d4c3fece11bf2 to your computer and use it in GitHub Desktop.
range in lua using coroutine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function range(n) | |
return coroutine.wrap(function() | |
for i = 1, n, 1 do | |
coroutine.yield(i) | |
end | |
end) | |
end | |
function main() | |
for i in range(10) do | |
print(i) | |
end | |
end | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment