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
coroutinestandard library — one(name_bytes, function_pointer)entry percoroutine.*function. The per-version roster (which entries actually register) is filtered inopen_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 functionf.- 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 coroutineco.- co_
running coroutine.running()— return the current coroutine plus a boolean.- co_
status coroutine.status(co)— return a string describingco’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
coroutinestandard library by pushing a new table containing allcoroutine.*functions.