aboutsummaryrefslogtreecommitdiffstats
path: root/src/systems/lua.cpp
blob: fa1e93e3d524cda764946a7a8a3445d7098f5fb4 (plain)
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
#include <systems/lua.hpp>

void LuaScript::setGlobal(const LuaVariable& nv)
{
	lua_pushnumber(state, std::get<float&>(nv));
	lua_setglobal(state, std::get<std::string>(nv).c_str());
}

void LuaScript::operator()(std::vector<LuaVariable> vars)
{
	for (auto& v : vars)
		setGlobal(v);
	(*this)();
	for (auto& v : vars) {
		lua_getglobal(state, std::get<std::string>(v).c_str());
		std::get<float&>(v) = lua_tonumber(state, -1);
	}
}

void LuaScript::operator()(void)
{
	lua_getglobal(state, "update");
	lua_pcall(state, 0, LUA_MULTRET, 0);
}