summaryrefslogtreecommitdiff
path: root/src/ui/screen_lua.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-11-20 14:43:20 +1100
committerjacqueline <me@jacqueline.id.au>2023-11-20 14:43:20 +1100
commiteffac1917a615660bf76b35b3605ac2d3eeabd2f (patch)
treee078b24b8405203fb36a6f83a7235b05f4bf32a0 /src/ui/screen_lua.cpp
parentb7f37f6426c78132d338b032962209bd93771039 (diff)
downloadtangara-fw-effac1917a615660bf76b35b3605ac2d3eeabd2f.tar.gz
Use C functions for the backstack, instead of a lua module
Working with the default group and root kinda sucks if you have to do it from lua!
Diffstat (limited to 'src/ui/screen_lua.cpp')
-rw-r--r--src/ui/screen_lua.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/ui/screen_lua.cpp b/src/ui/screen_lua.cpp
index cee5186e..ae49ffd5 100644
--- a/src/ui/screen_lua.cpp
+++ b/src/ui/screen_lua.cpp
@@ -6,13 +6,26 @@
#include "screen_lua.hpp"
+#include "lauxlib.h"
+#include "lua.h"
#include "lua.hpp"
#include "luavgl.h"
namespace ui {
namespace screens {
-Lua::Lua(lua_State* l) {
+Lua::Lua() : s_(nullptr), obj_ref_() {}
+
+Lua::~Lua() {
+ if (s_ && obj_ref_) {
+ luaL_unref(s_, LUA_REGISTRYINDEX, *obj_ref_);
+ }
+}
+
+auto Lua::SetObjRef(lua_State* s) -> void {
+ assert(s_ == nullptr);
+ s_ = s;
+ obj_ref_ = luaL_ref(s, LUA_REGISTRYINDEX);
}
} // namespace screens