Library coroutine

Coroutine library

Functions

create (func) Creates a new coroutine.
resume (thread, ...) Resumes a suspended coroutine.
running () Returns the coroutine that is currently running.
status (thread) Returns the status of the coroutine.
wait (time) Suspends the coroutine for a number of seconds.
wrap (func) Creates a new coroutine.
yield (...) Suspends the currently running coroutine.


Functions

coroutine_library.create (func)
Creates a new coroutine.

Parameters:

  • func: Function of the coroutine

Return value:

    coroutine
coroutine_library.resume (thread, ...)
Resumes a suspended coroutine. Note that, in contrast to Lua's native coroutine.resume function, it will not run in protected mode and can throw an error.

Parameters:

  • thread: coroutine to resume
  • ...: optional parameters that will be passed to the coroutine

Return value:

    Any values the coroutine is returning to the main thread
coroutine_library.running ()
Returns the coroutine that is currently running.

Return value:

    Currently running coroutine
coroutine_library.status (thread)
Returns the status of the coroutine.

Parameters:

  • thread: The coroutine

Return value:

    Either "suspended", "running", "normal" or "dead"
coroutine_library.wait (time)
Suspends the coroutine for a number of seconds. Note that the coroutine will not resume automatically, but any attempts to resume the coroutine while it is waiting will not resume the coroutine and act as if the coroutine suspended itself immediately.

Parameters:

  • time: Time in seconds to suspend the coroutine
coroutine_library.wrap (func)
Creates a new coroutine.

Parameters:

  • func: Function of the coroutine

Return value:

    A function that, when called, resumes the created coroutine. Any parameters to that function will be passed to the coroutine.
coroutine_library.yield (...)
Suspends the currently running coroutine. May not be called outside a coroutine.

Parameters:

  • ...: optional parameters that will be returned to the main thread

Return value:

    Any values passed to the coroutine

Valid XHTML 1.0!