diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-11-22 15:46:46 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-11-22 15:46:46 +1100 |
| commit | 9eb5ae6e946651bdbe532b66700bb1ed6944584f (patch) | |
| tree | 91a69573e4c481ff97c598213b08aa41e61aab76 /src/ui | |
| parent | 06aca259cbb84c41a002e5a93735b289cc2aa93a (diff) | |
| download | tangara-fw-9eb5ae6e946651bdbe532b66700bb1ed6944584f.tar.gz | |
Use protected mode for lua callbacks wherever possible
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/include/ui_events.hpp | 4 | ||||
| -rw-r--r-- | src/ui/include/ui_fsm.hpp | 3 | ||||
| -rw-r--r-- | src/ui/ui_fsm.cpp | 7 |
3 files changed, 12 insertions, 2 deletions
diff --git a/src/ui/include/ui_events.hpp b/src/ui/include/ui_events.hpp index b8dd459c..6a6be304 100644 --- a/src/ui/include/ui_events.hpp +++ b/src/ui/include/ui_events.hpp @@ -24,6 +24,10 @@ struct OnStorageChange : tinyfsm::Event { struct OnSystemError : tinyfsm::Event {}; + struct OnLuaError : tinyfsm::Event { + std::string message; + }; + namespace internal { struct RecordSelected : tinyfsm::Event { diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index d3ea7eac..9e81259a 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -64,6 +64,7 @@ class UiState : public tinyfsm::Fsm<UiState> { void react(const audio::QueueUpdate&); virtual void react(const system_fsm::KeyLockChanged&); + virtual void react(const OnLuaError&) {} virtual void react(const internal::RecordSelected&) {} virtual void react(const internal::IndexSelected&) {} @@ -124,6 +125,8 @@ class Lua : public UiState { void entry() override; void exit() override; + void react(const OnLuaError&) override; + void react(const internal::IndexSelected&) override; void react(const internal::ShowNowPlaying&) override; void react(const internal::ShowSettingsPage&) override; diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index ed0624df..5b4ea2a7 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -238,8 +238,7 @@ auto Lua::PushLuaScreen(lua_State* s) -> int { // Call the constructor for this screen. lua_settop(s, 1); // Make sure the function is actually at top of stack - // FIXME: This should ideally be lua_pcall, for safety. - lua_call(s, 0, 1); + lua::CallProtected(s, 0, 1); // Store the reference for the table the constructor returned. new_screen->SetObjRef(s); @@ -262,6 +261,10 @@ void Lua::exit() { lv_group_set_default(NULL); } +void Lua::react(const OnLuaError& err) { + ESP_LOGE("lua", "%s", err.message.c_str()); +} + void Lua::react(const internal::IndexSelected& ev) { auto db = sServices->database().lock(); if (!db) { |
