SimpleFastOpenAtomicVisualiser
Loading...
Searching...
No Matches
LuaTable.h
Go to the documentation of this file.
1#ifndef LUATABLE
2#define LUATABLE
3
4#include <lua.h>
5
6#include <vector>
7
13template <class LUA_TYPE>
15{
21
28 void read(lua_State * lua, int index)
29 {
30 unsigned length = lua_rawlen(lua,index);
31 data.resize(length);
32
33 for (unsigned i = 1; i <= length; i++)
34 {
35 lua_pushnumber(lua, i);
36 lua_gettable(lua, index);
37 data[i-1].read(lua, lua_gettop(lua));
38
39 lua_pop(lua, 1);
40 }
41 }
42
51 bool readField(lua_State * lua, const char * name)
52 {
53 int returnType = lua_getfield(lua, 1, name);
54
56 {
57 read(lua, 2);
58 lua_pop(lua,1);
59 return true;
60 }
61 else
62 {
63 lua_pop(lua,1);
64 return false;
65 }
66 }
67
76 bool readGlobal(lua_State * lua, const char * name)
77 {
78 int returnType = lua_getglobal(lua, name);
79
81 {
82 read(lua, 2);
83 lua_pop(lua,1);
84 return true;
85 }
86 else
87 {
88 lua_pop(lua,1);
89 return false;
90 }
91 }
92
93
94 size_t size() const { return data.size(); }
95
96 LUA_TYPE & operator [] (size_t i){ return data[i]; }
97
98 operator std::vector<LUA_TYPE>() { return data; }
99
100 std::vector<LUA_TYPE> data;
101};
102
103#endif /* LUATABLE */
glm::vec< L, float, glm::qualifier::highp > vec
Definition commandLine.h:214
Interop for a single-type Lua table.
Definition LuaTable.h:15
bool readField(lua_State *lua, const char *name)
Read the table from a table field.
Definition LuaTable.h:51
LuaTable()
Construct an default table.
Definition LuaTable.h:20
size_t size() const
Definition LuaTable.h:94
LUA_TYPE & operator[](size_t i)
Definition LuaTable.h:96
bool readGlobal(lua_State *lua, const char *name)
Read the table from a global table field.
Definition LuaTable.h:76
std::vector< LUA_TYPE > data
Definition LuaTable.h:100
void read(lua_State *lua, int index)
Read the table from stack index index.
Definition LuaTable.h:28