Script lps_coroutine.lua

Godot Reference script that wraps a Lua coroutine with an API similar to GDScriptFunctionState.

These are created by GD.yield and won't work if created manually.

Functions

get_status () Returns the coroutine.status.
is_valid () Returns whether coroutine is valid (self:get_status() ~= 'dead').
resume (...) Resume a coroutine, similar to coroutine.resume.

Fields

completed signal completed(result): signal emitted by resume when the coroutine body is completed.
status Result of coroutine.status


Functions

get_status ()
Returns the coroutine.status.

Returns:

    string

See also:

is_valid ()
Returns whether coroutine is valid (self:get_status() ~= 'dead').

Returns:

    bool
resume (...)
Resume a coroutine, similar to coroutine.resume. Emits the completed signal if the coroutine body is completed. Differently than GDScriptFunctionState.resume, this method accepts multiple arguments.

Parameters:

  • ...

Returns:

Raises:

If coroutine.resume returns false

Usage:

    local coro = some_object:method_that_yields()
    local first_value = coro:resume()
    local second_value = coro:resume()
    while coro:is_valid() do
        local next_value = coro:resume()
        -- do something
    end

Fields

completed
signal completed(result): signal emitted by resume when the coroutine body is completed.
status
Result of coroutine.status
generated by LDoc 1.4.6 Last updated 2023-01-04 08:52:34