Skip to main content

push_cclosure

Function push_cclosure 

Source
pub fn push_cclosure(
    state: &mut LuaState,
    f: fn(&mut LuaState) -> Result<usize, LuaError>,
    n: i32,
) -> Result<(), LuaError>
Expand description

C’s lua_pushcclosure: register f, then push either a light C function (n == 0) or a C closure that captures the top n stack values as upvalues.

The n > 0 branch builds the closure inline rather than delegating to state.new_c_closure, because it must populate the upvalue slots from the stack; new_c_closure only performs the object step (nil-initialised upvalues), leaving the stack fill to the caller.