Primer also provides a header so that you can push std::function
objects directly to lua.
The idea is that it takes the signature R(Args...) from the std::function
type, and puts that signature through PRIMER_ADAPT.
The std::function object itself is stored in userdata
as an upvalue to a closure, and the extracted arguments are passed to it
when it is invoked.
Example Usage:
std::function<primer::result(lua_State * L, int x, int y)> f = [](lua_State * L, int x, int y) -> primer::result { if (y == x) { return primer::error{"bad input"}; } lua_pushinteger(L, x - y); return 1; }; primer::push_std_function(L, std::move(f));
![]() |
Note |
|---|---|
|
We only provide this feature for convenience in a pure lua (not eris) application. |
![]() |
Caution |
|---|---|
The |