summaryrefslogtreecommitdiff
path: root/src/ui/screen_lua.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-03-21 10:50:23 +1100
committerjacqueline <me@jacqueline.id.au>2024-03-21 10:50:23 +1100
commit684ff50ef4931aeb8cfb15c5a2d62e55520f04a5 (patch)
treed7dc003eb1fd7b1a4960cb05d8084f18ddf64b72 /src/ui/screen_lua.cpp
parent21ae6a962623c9128fbb4a599cc50a2c616e9884 (diff)
downloadtangara-fw-684ff50ef4931aeb8cfb15c5a2d62e55520f04a5.tar.gz
Add support for screens declaring that they can't be popped
Needed as prep for usb msc support; you really shouldn't leave the MSC settings screen until you've disabled usb msc.
Diffstat (limited to 'src/ui/screen_lua.cpp')
-rw-r--r--src/ui/screen_lua.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ui/screen_lua.cpp b/src/ui/screen_lua.cpp
index d6c7a26f..55eef119 100644
--- a/src/ui/screen_lua.cpp
+++ b/src/ui/screen_lua.cpp
@@ -58,6 +58,25 @@ auto Lua::onHidden() -> void {
lua_pop(s_, 1);
}
+auto Lua::canPop() -> bool {
+ if (!s_ || !obj_ref_) {
+ return true;
+ }
+ lua_rawgeti(s_, LUA_REGISTRYINDEX, *obj_ref_);
+ lua_pushliteral(s_, "canPop");
+
+ if (lua_gettable(s_, -2) == LUA_TFUNCTION) {
+ // If we got a callback instead of a value, then invoke it to turn it into
+ // value.
+ lua_pushvalue(s_, -2);
+ lua::CallProtected(s_, 1, 1);
+ }
+ bool ret = lua_toboolean(s_, -1);
+
+ lua_pop(s_, 2);
+ return ret;
+}
+
auto Lua::SetObjRef(lua_State* s) -> void {
assert(s_ == nullptr);
s_ = s;