nngn
Loading...
Searching...
No Matches
function.h
Go to the documentation of this file.
1
64#ifndef NNGN_LUA_FUNCTION_H
65#define NNGN_LUA_FUNCTION_H
66
67#include <optional>
68#include <tuple>
69#include <utility>
70
71#include <lua.hpp>
72
73#include "utils/log.h"
74
75#include "lua.h"
76#include "push.h"
77#include "state.h"
78#include "utils.h"
79#include "value.h"
80
81namespace nngn::lua {
82
83namespace detail {
84
86template<typename CRTP>
89 void operator()(auto &&...args) const;
90};
91
92}
93
100};
101
111
112namespace detail {
113
114template<typename CRTP>
115void function_base<CRTP>::operator()(auto &&...args) const {
117 const auto &crtp = static_cast<const CRTP&>(*this);
118 crtp.state().call(crtp, FWD(args)...);
119}
120
121}
122
124template<typename R, typename ...Args>
125R call(lua_State *L, R(*f)(Args...), int i) {
126 return std::apply(f, stack_get<std::tuple<Args...>>::get(L, i));
127}
128
130template<typename R, typename T, typename ...Args>
131R call(lua_State *L, R(T::*f)(Args...), int i) {
132 return std::apply(f, stack_get<std::tuple<T&, Args...>>::get(L, i));
133}
134
136template<typename R, typename T, typename ...Args>
137R call(lua_State *L, R(T::*f)(Args...) const, int i) {
138 return std::apply(f, stack_get<std::tuple<const T&, Args...>>::get(L, i));
139}
140
142template<stateless_lambda T>
143decltype(auto) call(lua_State *L, T, int i) {
144 return call(L, +T{}, i);
145}
146
147static_assert(detail::stack_type<function_view>);
148static_assert(detail::stack_type<function_value>);
149
150}
151
152#endif
local class const
Definition animation.lua:7
Base, non-owning generic stack value reference.
Definition value.h:18
precision highp int
Definition common.h:14
for i
Definition font.lua:5
#define T(f0, f1, f2)
#define NNGN_LOG_CONTEXT_CF(c)
Definition log.h:11
Definition lua_audio.cpp:19
R call(lua_State *L, R(*f)(Args...), int i)
Calls the regular function f with arguments taken from the stack.
Definition function.h:125
Functions for pushing values onto the stack.
get
Definition camera.lua:46
local function f()) end
General utilities for stack manipulation.
#define FWD(...)
Definition utils.h:18
#define NNGN_MOVE_ONLY(x)
Definition utils.h:39
lua_State wrappers.
Reference to a function on the stack.
Definition function.h:87
void operator()(auto &&...args) const
Pushes each argument onto the stack and calls the function.
Definition function.h:115
Owning reference to a function on the stack.
Definition function.h:106
~function_value(void)=default
Non-owning reference to a function on the stack.
Definition function.h:98
Reads a value from the Lua stack.
Definition lua.h:118
Owning stack value reference.
Definition value.h:48
value(const value &)=delete
Operations on generic stack values.