summaryrefslogtreecommitdiff
path: root/src/ui/screen_lua.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-03-07 11:23:31 +1100
committerjacqueline <me@jacqueline.id.au>2024-03-07 11:23:31 +1100
commitbeb1f654958c28429323fcb9622c9c8d206979a3 (patch)
tree2e81e643a6099e5a9e884dbe2346dd2e761751e1 /src/ui/screen_lua.cpp
parent14552881900bb3ed0e9ed2d4a732e4104b32ccfa (diff)
parenteba5adeb8cc606b4d685132248c6481c0aca53f6 (diff)
downloadtangara-fw-beb1f654958c28429323fcb9622c9c8d206979a3.tar.gz
Merge branch 'main' of git.sr.ht:~jacqueline/tangara-fw
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 5130b4f7..d6c7a26f 100644
--- a/src/ui/screen_lua.cpp
+++ b/src/ui/screen_lua.cpp
@@ -7,8 +7,10 @@
#include "screen_lua.hpp"
#include "core/lv_obj_tree.h"
+#include "lua.h"
#include "lua.hpp"
+#include "lua_thread.hpp"
#include "luavgl.h"
namespace ui {
@@ -22,6 +24,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;