48#include "utils/concepts.h"
49#include "utils/fixed_string.h"
51#include "utils/ranges.h"
52#include "utils/utils.h"
64#define NNGN_LUA_TYPES(X) \
67 X(boolean, LUA_TBOOLEAN) \
68 X(light_user_data, LUA_TLIGHTUSERDATA) \
69 X(number, LUA_TNUMBER) \
70 X(string, LUA_TSTRING) \
71 X(table, LUA_TTABLE) \
72 X(function, LUA_TFUNCTION) \
73 X(user_data, LUA_TUSERDATA) \
74 X(thread, LUA_TTHREAD)
84inline constexpr struct nil_type {}
nil;
87template<
typename T>
struct error {
T e; };
93inline constexpr std::array
types = [] {
94 using U = std::underlying_type_t<type>;
95 constexpr auto f = to_underlying<type>;
97 constexpr auto n =
e - b;
98 std::array<U, n> u = {};
99 std::array<type, n> ret = {};
102 std::ranges::begin(u), std::ranges::end(u),
103 std::ranges::begin(ret),
to<type>{});
118template<
typename>
struct stack_get;
120template<
typename =
void>
struct stack_push;
134 static int push(lua_State *L,
T &&t) {
145template<
typename T>
inline constexpr auto is_user_type =
false;
148template<
typename T>
concept user_type = is_user_type<std::decay_t<T>>;
158template<
typename R,
typename ...Args>
159R
call(lua_State *L, R(*
f)(Args...),
int i = 1);
160template<
typename R,
typename T,
typename ...Args>
161R
call(lua_State *L, R(
T::*
f)(Args...),
int i = 1);
162template<
typename R,
typename T,
typename ...Args>
163R
call(lua_State *L, R(
T::*
f)(Args...)
const,
int i = 1);
164template<stateless_lambda T>
165decltype(
auto)
call(lua_State *L,
T,
int i = 1);
169template<
typename CRTP,
typename T>
class table_iter_base;
170template<
typename T>
class table_iter;
171template<
typename T>
class table_seq_iter;
176struct table_base_tag {};
179struct table_proxy_tag {};
183inline constexpr bool can_get =
requires(lua_State *L) {
189inline constexpr bool can_push =
requires(lua_State *L,
T t) {
199concept stack_type =
requires(lua_State *L,
int i,
T t) {
201 { t.state() } -> std::same_as<state_view>;
202 { t.push() } -> std::same_as<int>;
213template<
typename T>
inline constexpr bool is_optional =
false;
214template<
typename T>
inline constexpr bool is_optional<std::optional<T>> =
true;
223template<
typename T>
inline constexpr bool is_stack_ref =
false;
229template<
typename T>
concept stack_ref = is_stack_ref<std::decay_t<T>>;
233int msgh(lua_State *L);
241#define X(n, _) case type::n: return #n;
244 default:
return "unknown";
As std::convertible_to, but excluding implicit conversions.
Definition: concepts.h:27
A type which can be fully represented by a lua_Integer.
Definition: lua.h:206
A type which can be fully represented by a lua_Number.
Definition: lua.h:210
A built-in type from this library with stack manipulation operations.
Definition: lua.h:198
A type which can be read from / pushed onto the stack.
Definition: lua.h:194
function DEMO text end
Definition: demo0.lua:6
for i
Definition: font.lua:5
assert
Definition: debug.lua:3
n
Definition: dump_lights.lua:5
#define NNGN_LUA_TYPES(X)
Definition: lua.h:64
error
Definition: strict.lua:2
#define FWD(...)
Definition: utils.h:18
constexpr bool is_optional
Definition: lua.h:212
op_mode
Definition: lua.h:172
@ raw
Definition: lua.h:172
@ normal
Definition: lua.h:172
constexpr bool can_push
Whether this library knows how to push a T value onto the stack.
Definition: lua.h:188
constexpr bool can_get
Whether this library knows how to read a T value from the stack.
Definition: lua.h:182
Definition: lua_audio.cpp:19
constexpr type type_from_lua(int t)
Maps LUA_T* values to type.
Definition: lua.h:108
void print_stack(lua_State *L)
Logs the current data stack.
Definition: lua.cpp:26
int msgh(lua_State *L)
Default message handler for lua_pcall.
Definition: lua.cpp:15
T push(nngn::lua::state_view lua, auto &&v)
Definition: state.h:186
std::string_view type_str(type t)
Definition: lua.h:238
constexpr bool is_stack_ref
Determines whether a type is a reference to a value on the stack.
Definition: lua.h:222
constexpr bool is_stack_ref< T >
Definition: table.h:452
type
LUA_T* constants as a scoped enumeration.
Definition: lua.h:77
constexpr auto is_user_type
Flag which indicates that a type is to be treated as a user type.
Definition: lua.h:144
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
constexpr struct nngn::lua::nil_type nil
constexpr empty metatable_name
Key in the global table where the meta-table for T is stored.
Definition: lua.h:155
void print_traceback(lua_State *L)
Logs the current call stack.
Definition: lua.cpp:59
constexpr const R * begin(const T< R > &v)
Definition: vec.h:207
constexpr auto to_underlying(T t)
Definition: utils.h:138
constexpr bool is_sequence(R &&r, Proj proj={})
Definition: ranges.h:119
empty
Definition: utils.h:89
"Pushing" this value causes lua_error to be called.
Definition: lua.h:86
Reads a value from the Lua stack.
Definition: lua.h:117
Pushes a value onto the Lua stack.
Definition: lua.h:119
Function object which converts its argument to T via static_cast.
Definition: fn.h:25