Coroutine API

From ComputerCraft
Jump to: navigation, search
FunctionFunctioncoroutine.create
Creates a thread from a function.
Syntax coroutine.create()
Returns thread
Part of Lua
API Base globals
ExampleExamplecreates a thread from a function.
Create a thread from the function "print".
Code
local co = coroutine.create(print)


FunctionFunctioncoroutine.resume
Resumes a coroutine.
Syntax coroutine.resume(
  • coroutine : any The coroutine to resume
  • ... : any Arguments to pass to the coroutine
)
Returns boolean
Part of Lua
API Base globals
ExampleExampleResume coroutine.
Resumes a coroutine with "test".
Code
local co = coroutine.create(function(x)
  print(x)
end)
coroutine.resume(co, "test")
Output
test

Coroutine.running Coroutine.status Coroutine.wrap

How To Use Coroutines
FunctionFunctioncoroutine.yield
Takes arguments {...} and makes the coroutine.resume call executing the coroutine calling this to return them (usually, this is just a single string acting as a filter for the type of event desired). Usually you should use os.pullEvent and os.pullEventRaw instead.
Syntax coroutine.yield(
    {...}
)
Returns {...}
Part of CC:Tweaked
API coroutine
See also os.pullEvent