SimpleFastOpenAtomicVisualiser
Loading...
Searching...
No Matches
lua.h
Go to the documentation of this file.
1#ifndef LUA_H
2#define LUA_H
3
4#include <vector>
5#include <array>
6#include <string>
7#include <stdexcept>
8#include <algorithm>
9
10extern "C"
11{
12 #include <lua/src/lua.h>
13 #include <lua/src/lauxlib.h>
14 #include <lua/src/lualib.h>
15}
16
24std::vector<double> getNumericLuaTable(lua_State * lua, int index)
25{
26 unsigned length = lua_rawlen(lua,index);
27 std::vector<double> values(length);
28
29 for (unsigned i = 1; i <= length; i++)
30 {
31 lua_pushnumber(lua,i);
32 // replaces number i (key) with the value
33 lua_gettable(lua,index);
34 values[i-1] = lua_tonumber(lua,-1);
35 lua_pop(lua,1);
36 }
37
38 return values;
39}
40
48std::vector<std::vector<double>> getLuaTableOfNumericLuaTable(lua_State * lua, int index)
49{
50 unsigned length = lua_rawlen(lua,index);
51 std::vector<std::vector<double>> values;
52
53 for (unsigned i = 1; i <= length; i++)
54 {
55 lua_pushnumber(lua,i);
56 lua_gettable(lua,index);
57
58 values.push_back
59 (
60 // not -1, since stack will be added to
61 // in this call, need absolute position
63 );
64
65 lua_pop(lua,1);
66 }
67 return values;
68}
69
78int lua_checkArgumentCount(lua_State * lua, int expected, std::string msg)
79{
80 int n = lua_gettop(lua);
81 if (n != expected)
82 {
83 lua_pushlstring(lua, msg.c_str(), msg.length());
84 return lua_error(lua);
85 }
86 return LUA_OK;
87}
88
89#endif /* LUA_H */
glm::vec< L, float, glm::qualifier::highp > vec
Definition commandLine.h:214
int lua_checkArgumentCount(lua_State *lua, int expected, std::string msg)
Check the number of arguments to the Lua call.
Definition lua.h:78
std::vector< double > getNumericLuaTable(lua_State *lua, int index)
Get the a Lua table of doubles.
Definition lua.h:24
std::vector< std::vector< double > > getLuaTableOfNumericLuaTable(lua_State *lua, int index)
Get the a Lua table of table of doubles.
Definition lua.h:48