summaryrefslogtreecommitdiff
path: root/src/ui/screen_lua.cpp
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2024-03-20 13:42:03 +1100
committerailurux <ailuruxx@gmail.com>2024-03-20 13:42:03 +1100
commit51dfb5b3e30caf823c2355ff957c01864f35f9f6 (patch)
tree1f0e41397259c6e206aba136ad5070b9de30e1b1 /src/ui/screen_lua.cpp
parent170c23b832eed6dad2b118e50164464cc93e5c4c (diff)
parenta05d93a1e26181237a76da5ce398c6b08497d591 (diff)
downloadtangara-fw-51dfb5b3e30caf823c2355ff957c01864f35f9f6.tar.gz
Merge branch 'main' into themes
Diffstat (limited to 'src/ui/screen_lua.cpp')
-rw-r--r--src/ui/screen_lua.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/ui/screen_lua.cpp b/src/ui/screen_lua.cpp
index b3554241..1ad4a8e8 100644
--- a/src/ui/screen_lua.cpp
+++ b/src/ui/screen_lua.cpp
@@ -7,9 +7,11 @@
#include "screen_lua.hpp"
#include "core/lv_obj_tree.h"
+#include "lua.h"
#include "lua.hpp"
#include "themes.hpp"
+#include "lua_thread.hpp"
#include "luavgl.h"
namespace ui {
@@ -25,6 +27,40 @@ Lua::~Lua() {
}
}
+auto Lua::onShown() -> void {
+ if (!s_ || !obj_ref_) {
+ return;
+ }
+ lua_rawgeti(s_, LUA_REGISTRYINDEX, *obj_ref_);
+ lua_pushliteral(s_, "onShown");
+
+ if (lua_gettable(s_, -2) == LUA_TFUNCTION) {
+ lua_pushvalue(s_, -2);
+ lua::CallProtected(s_, 1, 0);
+ } else {
+ lua_pop(s_, 1);
+ }
+
+ lua_pop(s_, 1);
+}
+
+auto Lua::onHidden() -> void {
+ if (!s_ || !obj_ref_) {
+ return;
+ }
+ lua_rawgeti(s_, LUA_REGISTRYINDEX, *obj_ref_);
+ lua_pushliteral(s_, "onHidden");
+
+ if (lua_gettable(s_, -2) == LUA_TFUNCTION) {
+ lua_pushvalue(s_, -2);
+ lua::CallProtected(s_, 1, 0);
+ } else {
+ lua_pop(s_, 1);
+ }
+
+ lua_pop(s_, 1);
+}
+
auto Lua::SetObjRef(lua_State* s) -> void {
assert(s_ == nullptr);
s_ = s;