nngn
|
Operations on callable types, function call implementation. More...
#include <optional>
#include <tuple>
#include <utility>
#include <lua.hpp>
#include "utils/log.h"
#include "lua.h"
#include "push.h"
#include "state.h"
#include "utils.h"
#include "value.h"
Go to the source code of this file.
Classes | |
struct | nngn::lua::detail::function_base< CRTP > |
Reference to a function on the stack. More... | |
struct | nngn::lua::function_view |
Non-owning reference to a function on the stack. More... | |
struct | nngn::lua::function_value |
Owning reference to a function on the stack. More... | |
Namespaces | |
namespace | nngn |
namespace | nngn::lua |
namespace | nngn::lua::detail |
Functions | |
template<typename R , typename ... Args> | |
R | nngn::lua::call (lua_State *L, R(*f)(Args...), int i) |
Calls the regular function f with arguments taken from the stack. | |
template<typename R , typename T , typename ... Args> | |
R | nngn::lua::call (lua_State *L, R(T::*f)(Args...), int i) |
Calls member function f with object/arguments taken from the stack. | |
template<stateless_lambda T> | |
nngn::lua::call (lua_State *L, T, int i) | |
Calls a stateless lambda. | |
Operations on callable types, function call implementation.
The main object which implements Lua function calls is function_base. Its operator()
pushes all arguments onto the stack and performs a lua_(p)call
(depending on debug/release settings). function_view and function_value are the equivalent of value_view and value with the function_base mixin.
An alternative group of functions is call, which can be thought of as the reverse of function_base: they are used to call C/++ functions and take arguments and return values from/to Lua stack. All arguments are assumed to be already on the stack; return values are pushed after the execution of the function. Because the types of arguments and return values are inferred from the function (pointer) argument to call, it must be a resolved value: an overloaded function must be cast, a function template must be explicitly instantiated, etc.
Calling a Lua function:
Pushing a C/++ function and calling it:
The same, but set and called through Lua:
Calling a C/++ function using stack values and pushing the result: