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
10#include <lua/src/lua.h>
11#include <lua/src/lauxlib.h>
12#include <lua/src/lualib.h>
13
21std::vector<double> getNumericLuaTable(lua_State * lua, int index)
22{
23 unsigned length = lua_rawlen(lua,index);
24 std::vector<double> values(length);
25
26 for (unsigned i = 1; i <= length; i++)
27 {
28 lua_pushnumber(lua,i);
29 // replaces number i (key) with the value
30 lua_gettable(lua,index);
31 values[i-1] = lua_tonumber(lua,-1);
32 lua_pop(lua,1);
33 }
34
35 return values;
36}
37
45std::vector<std::vector<double>> getLuaTableOfNumericLuaTable(lua_State * lua, int index)
46{
47 unsigned length = lua_rawlen(lua,index);
48 std::vector<std::vector<double>> values;
49
50 for (unsigned i = 1; i <= length; i++)
51 {
52 lua_pushnumber(lua,i);
53 lua_gettable(lua,index);
54
55 values.push_back
56 (
57 // not -1, since stack will be added to
58 // in this call, need absolute position
60 );
61
62 lua_pop(lua,1);
63 }
64 return values;
65}
66
75int lua_checkArgumentCount(lua_State * lua, int expected, std::string msg)
76{
77 int n = lua_gettop(lua);
78 if (n != expected)
79 {
80 lua_pushlstring(lua, msg.c_str(), msg.length());
81 return lua_error(lua);
82 }
83 return LUA_OK;
84}
85
86#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:75
std::vector< double > getNumericLuaTable(lua_State *lua, int index)
Get the a Lua table of doubles.
Definition lua.h:21
std::vector< std::vector< double > > getLuaTableOfNumericLuaTable(lua_State *lua, int index)
Get the a Lua table of table of doubles.
Definition lua.h:45