May 2017
Intermediate to advanced
416 pages
21h 33m
English
To execute a coroutine, use the function coroutine.resume:
coroutine.resume(<coroutine>)
You can also pass parameters to the coroutine function as additional arguments to the coroutine.resume function:
local nt = coroutine.create(function(x, y, z) print(x,y,z) end) coroutine.resume(nt, 1, 2, 3)
The output will be as follows:
1,2,3
There is a function named coroutine.wrap that can replace the need of running coroutine.create and coroutine.resume. The only difference is that the coroutine must be assigned to a function:
local ntwrapped = coroutine.wrap(function() print("w00t!") end) ntwrapped() --Will print w00t!
Read now
Unlock full access