aboutsummaryrefslogtreecommitdiffstats
path: root/src/systems/lua.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-09-28 17:28:59 -0400
committerClyne Sullivan <tullivan99@gmail.com>2017-09-28 17:28:59 -0400
commitbabd5e5596cefc7b2e15825976e084591f275d6f (patch)
tree9f7eeb7fd0c375e95c44f4257849f40676965a80 /src/systems/lua.cpp
parent3ffd09ad483a77053ebc566c3ab464a1c85e7a44 (diff)
lua - references
Diffstat (limited to 'src/systems/lua.cpp')
-rw-r--r--src/systems/lua.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/systems/lua.cpp b/src/systems/lua.cpp
index b093aff..fa1e93e 100644
--- a/src/systems/lua.cpp
+++ b/src/systems/lua.cpp
@@ -1,2 +1,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);
+}
+