Skip to main content

Module coro_lib

Module coro_lib 

Source
Expand description

Coroutine library — the coroutine.* standard-library table: create, resume, running, status, wrap, yield, isyieldable, and close.

This module is the cold shell around coroutine execution: argument checking, the COS_* status-string mapping, the wrap closure setup, the cross-thread argument/result transfer scaffolding, and version-gated registration. The actual control transfer — resume/yield stack save and restore — lives in lua-vm (lua_vm::do_::lua_resume / lua_yieldk) and is load-bearing; this module calls into it but does not implement it.

§Graduation (Idiomatization Sprint 2, Phase 2 — coroutine)

Idiomatized AROUND the resume/yield machinery, never through it. The behavioral net guarding this module’s cold surface is crates/lua-stdlib/tests/coro_strengthen.rs (the version seams: running arity 5.1-vs-5.2+, isyieldable 5.3+, close 5.4+ + its suspended→dead transition and the 5.4-errors/5.5-unwinds self-close, the resume/wrap error wording, status transitions across a yield) plus the official coroutine.lua suite and multiversion_oracle. Net-strengthening caught one real bug: the resume-of-running error used the 5.2+ wording on 5.1 — fixed via non_suspended_resume_message. Left load-bearing: the cross-thread snapshot/rooting (RootedThreadBorrow, the resume-pool buffers, the GC stack snapshots), the LuaThreadClose panic-unwind path that implements 5.5 self-close, and every version gate.

Constants§

CO_FUNCS
Registration table for the coroutine standard library — one (name_bytes, function_pointer) entry per coroutine.* function. The per-version roster (which entries actually register) is filtered in open_coroutine; this table is the full superset.

Functions§

co_close
coroutine.close(co) — close a dead or suspended coroutine.
co_create
coroutine.create(f) — create a new coroutine that will run function f.
co_isyieldable
coroutine.isyieldable([co]) — test whether a coroutine (default: current) is in a yieldable state.
co_resume
coroutine.resume(co [, val1, ...]) — attempt to resume coroutine co.
co_running
coroutine.running() — return the current coroutine plus a boolean.
co_status
coroutine.status(co) — return a string describing co’s current status.
co_wrap
coroutine.wrap(f) — create a coroutine and return a resuming function.
co_yield
coroutine.yield([...]) — suspend the running coroutine.
open_coroutine
Opens the coroutine standard library by pushing a new table containing all coroutine.* functions.