pub unsafe fn pushfunction<FUNC>(state: lua_State, callback: FUNC)
Expand description
Pushes rust function/closure to lua stack.
ยงExample
let state = newstate();
createtable(state, 0, 2);
pushfunction(state, |_| {
println!("Hello there!");
Ok(0)
});
setfield(state, -2, cstr!("test_immutable_closure"));
fn test_function(state: lua_State) -> Result {
println!("Hello there, but from functuin, I guess.");
Ok(0)
}
pushfunction(state, test_function);
setfield(state, -2, cstr!("test_immutable_function"));
let mut counter = 0;
pushfunction_mut(state, move |_| {
println!("Here is yout counter!: {}", counter);
pushinteger(state, counter);
counter += 1;
Ok(1)
});
setfield(state, -2, cstr!("test_mutable_closure"));
setfield(state, GLOBALSINDEX, cstr!("tests"));