-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_lua.cc
44 lines (36 loc) · 893 Bytes
/
config_lua.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "config_lua.hh"
void config::lua::rewind(unsigned long long ts)
{
getglobal("load_history");
if (isfunction()){
// There is a load_history function.
pushinteger(ts);
newtable();
unsigned cnt = 0;
std::for_each(known.begin(), known.end(),
[&cnt, this] (const auto& name) {
this->pushinteger(++cnt);
this->pushstring(name);
this->settable(-3);
});
call(2, 1);
pop();
}
}
void config::lua::get_value(const char* str, int (*typechk)(lua_State*, int))
{
getglobal(str);
auto t = type();
while (isfunction()) {
call(0, 1);
t = type();
}
if (typechk(state, -1))
return;
// Error handling.
pop();
if (t == LUA_TNIL)
throw std::out_of_range("undefined value");
else
throw std::invalid_argument("unexpected value");
}