diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-02-22 12:37:01 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-02-22 12:37:01 +1100 |
| commit | 4b2003c78a5e4270f384283f72d185cd4a40f30e (patch) | |
| tree | 6db70733ece111762f5aaf178d082716d8bd702a /src/lua/include/lua_thread.hpp | |
| parent | 2a250855036047f4e3e37e51600276746d1c302a (diff) | |
| download | tangara-fw-4b2003c78a5e4270f384283f72d185cd4a40f30e.tar.gz | |
Make property bindings shared amongst all lua threads
Diffstat (limited to 'src/lua/include/lua_thread.hpp')
| -rw-r--r-- | src/lua/include/lua_thread.hpp | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/lua/include/lua_thread.hpp b/src/lua/include/lua_thread.hpp index d10dba3a..c12a0bfc 100644 --- a/src/lua/include/lua_thread.hpp +++ b/src/lua/include/lua_thread.hpp @@ -23,8 +23,7 @@ auto CallProtected(lua_State*, int nargs, int nresults) -> int; class LuaThread { public: - static auto Start(system_fsm::ServiceLocator&, lv_obj_t* lvgl_root = nullptr) - -> LuaThread*; + static auto Start(system_fsm::ServiceLocator&) -> LuaThread*; ~LuaThread(); auto RunScript(const std::string& path) -> bool; @@ -32,15 +31,48 @@ class LuaThread { auto DumpStack() -> void; - auto bridge() -> Bridge& { return *bridge_; } auto state() -> lua_State* { return state_; } + LuaThread(const LuaThread&) = delete; + LuaThread& operator=(const LuaThread&) = delete; + private: - LuaThread(std::unique_ptr<Allocator>&, std::unique_ptr<Bridge>&, lua_State*); + LuaThread(std::unique_ptr<Allocator>&, lua_State*); std::unique_ptr<Allocator> alloc_; - std::unique_ptr<Bridge> bridge_; lua_State* state_; }; +class Registry { + public: + static auto instance(system_fsm::ServiceLocator&) -> Registry&; + + auto uiThread() -> std::shared_ptr<LuaThread>; + auto newThread() -> std::shared_ptr<LuaThread>; + + auto AddPropertyModule( + const std::string&, + std::vector< + std::pair<std::string, std::variant<LuaFunction, Property*>>>) + -> void; + + Registry(const Registry&) = delete; + Registry& operator=(const Registry&) = delete; + + private: + Registry(system_fsm::ServiceLocator&); + + system_fsm::ServiceLocator& services_; + std::unique_ptr<Bridge> bridge_; + + std::shared_ptr<LuaThread> ui_thread_; + std::list<std::weak_ptr<LuaThread>> threads_; + + std::vector< + std::pair<std::string, + std::vector<std::pair<std::string, + std::variant<LuaFunction, Property*>>>>> + modules_; +}; + } // namespace lua |
