coroutine.create

Creates a new coroutine thread

Prototype

thread = coroutine.create (f)

Description

Creates a thread consisting of the body f.

thread = coroutine.create (f)
Then you can resume it with coroutine.resume.

For example:

function f (a, b, c)
  print (a, b, c)
end -- f

thread = coroutine.create (f)  -- thread will run function f
assert (coroutine.resume (thread, 1, 2, 3))  -- start thread, passing arguments: 1, 2, 3

Lua functions

Topics