LuaCFunction typedef
The most basic function type that can be pushed, similar to lua_CFunction
in reference Lua.
To get the number of arguments use LuaState.top and access them using LuaState.at, Example:
state.push((LuaState fstate) {
// Sum all parameters
fstate.push(fstate.values(top).fold(0, (e, s) => e + s));
return 1; // Return 1 value
});
print(state.call([1234, 5678])); // Should print [6912]
Always push values to the state parameter instead of the state you push the function to as the function can be called from a different state i.e. inside of a coroutine.
Implementation
typedef LuaCFunction = int Function(LuaState state);