SimpleFastOpenAtomicVisualiser
Loading...
Searching...
No Matches
LuaVec.h
Go to the documentation of this file.
1#ifndef LUAVEC
2#define LUAVEC
3
4#include <lua.h>
5#include <vector>
6
11struct LuaVec
12{
18
25 void read(lua_State * lua, int index)
26 {
27 elements = getNumericLuaTable(lua, index);
28 }
29
38 bool readField(lua_State * lua, const char * name)
39 {
40 int returnType = lua_getfield(lua, 1, name);
41
43 {
44 read(lua, 2);
45 lua_pop(lua,1);
46 return true;
47 }
48 else
49 {
50 lua_pop(lua,1);
51 return false;
52 }
53 }
54
63 bool readGlobal(lua_State * lua, const char * name)
64 {
65 int returnType = lua_getglobal(lua, name);
66
68 {
69 read(lua, 2);
70 lua_pop(lua,1);
71 return true;
72 }
73 else
74 {
75 lua_pop(lua,1);
76 return false;
77 }
78 }
79
80
81 double & operator [] (size_t i){ return elements[i]; }
82
83 size_t size() const { return elements.size(); }
84
85 operator std::vector<double>() { return elements; }
86
87 std::vector<double> elements;
88};
89
90#endif /* LUAVEC */
glm::vec< L, float, glm::qualifier::highp > vec
Definition commandLine.h:214
std::vector< double > getNumericLuaTable(lua_State *lua, int index)
Get the a Lua table of doubles.
Definition lua.h:24
Interop for a variable size numeric array (vector) in Lua.
Definition LuaVec.h:12
bool readField(lua_State *lua, const char *name)
Read the vector from a table field.
Definition LuaVec.h:38
double & operator[](size_t i)
Definition LuaVec.h:81
size_t size() const
Definition LuaVec.h:83
LuaVec()
Construct an empty vector.
Definition LuaVec.h:17
std::vector< double > elements
Definition LuaVec.h:87
bool readGlobal(lua_State *lua, const char *name)
Read the vector from a global table field.
Definition LuaVec.h:63
void read(lua_State *lua, int index)
Read the vector from stack index index.
Definition LuaVec.h:25