nngn
Loading...
Searching...
No Matches
lua_vector.h
Go to the documentation of this file.
1#ifndef NNGN_MATH_LUA_VECTOR_H
2#define NNGN_MATH_LUA_VECTOR_H
3
4#include <cstddef>
5#include <vector>
6
7#include "lua/register.h"
8#include "lua/user.h"
9
10namespace nngn {
11
13template<typename T>
14class lua_vector : public std::vector<T> {
15 using base_type = typename std::vector<T>;
16public:
17 using base_type::base_type;
19 explicit lua_vector(lua_Integer n)
20 : base_type(nngn::narrow<std::size_t>(n)) {}
21 explicit lua_vector(base_type &&rhs) : base_type{FWD(rhs)} {}
22};
23
24}
25
26namespace nngn::lua {
27
28template<typename T>
30 static lua_vector<T> *get(lua_State *L, int i) {
32 }
33};
34
35template<typename T>
37 static const lua_vector<T> &get(lua_State *L, int i) {
38 return *stack_get<lua_vector<T>*>::get(L, i);
39 }
40};
41
42template<typename T>
44 static int push(lua_State *L, lua_vector<T> v) {
45 return user_data<lua_vector<T>>::push(L, std::move(v));
46 }
47};
48
49}
50
52NNGN_LUA_DECLARE_USER_TYPE(nngn::lua_vector<std::byte>, "vector<byte>")
53
54#endif
local class const
Definition animation.lua:7
Data block allocated for user data objects.
Definition user.h:73
Type used to get/push vectors as user data in Lua.
Definition lua_vector.h:14
lua_vector(lua_Integer n)
Convenience n-element construction from a lua_Integer.
Definition lua_vector.h:19
typename std::vector< T > base_type
Definition lua_vector.h:15
lua_vector(base_type &&rhs)
Definition lua_vector.h:21
for i
Definition font.lua:5
local n
Definition dump_lights.lua:5
#define T(f0, f1, f2)
Definition lua_audio.cpp:19
T push(nngn::lua::state_view lua, auto &&v)
Definition state.h:186
Definition audio.cpp:7
To narrow(const From &x)
Casts x to a narrower type, asserting that the value is preserved.
Definition utils.h:101
Definition debug.h:13
Functions/macros for registering user types.
#define NNGN_LUA_DECLARE_USER_TYPE(T,...)
Declares that T objects should be manipulated as a user type.
Definition register.h:124
get
Definition camera.lua:46
v[1]
Definition math.lua:22
#define FWD(...)
Definition utils.h:18
static const lua_vector< T > & get(lua_State *L, int i)
Definition lua_vector.h:37
static lua_vector< T > * get(lua_State *L, int i)
Definition lua_vector.h:30
Reads a value from the Lua stack.
Definition lua.h:118
static int push(lua_State *L, lua_vector< T > v)
Definition lua_vector.h:44
Pushes a value onto the Lua stack.
Definition lua.h:120
Operations on light/full user data values.