From effac1917a615660bf76b35b3605ac2d3eeabd2f Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 20 Nov 2023 14:43:20 +1100 Subject: 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! --- src/ui/screen_lua.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/ui/screen_lua.cpp') 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 -- cgit v1.2.3