Skip to main content

co_create

Function co_create 

Source
pub fn co_create(state: &mut LuaState) -> Result<usize, LuaError>
Expand description

coroutine.create(f) — create a new coroutine that will run function f.

Pushes the new thread value and returns 1.

Phase E-1: allocates a real LuaState registered in GlobalState::threads, with f staged on the new thread’s stack so coroutine.status reports "suspended". The full xmove from the caller’s stack arrives in slice 02b; for this slice the body is cloned via value_at(1), which has the same net stack effect since lua_newthread in C also leaves only the thread value on the caller’s stack.

C: static int luaB_cocreate(lua_State *L)