/* * Copyright 2023 jacqueline * * SPDX-License-Identifier: GPL-3.0-only */ #pragma once #include #include #include "lua.hpp" #include "lvgl.h" #include "bridge.hpp" #include "service_locator.hpp" namespace lua { class Allocator; auto CallProtected(lua_State*, int nargs, int nresults) -> int; class LuaThread { public: static auto Start(system_fsm::ServiceLocator&) -> LuaThread*; ~LuaThread(); auto RunScript(const std::string& path) -> bool; auto RunString(const std::string& path) -> bool; auto DumpStack() -> void; auto state() -> lua_State* { return state_; } LuaThread(const LuaThread&) = delete; LuaThread& operator=(const LuaThread&) = delete; private: LuaThread(std::unique_ptr&, lua_State*); std::unique_ptr alloc_; lua_State* state_; }; class Registry { public: static auto instance(system_fsm::ServiceLocator&) -> Registry&; auto uiThread() -> std::shared_ptr; auto newThread() -> std::shared_ptr; auto AddPropertyModule( const std::string&, std::vector< std::pair>>) -> void; Registry(const Registry&) = delete; Registry& operator=(const Registry&) = delete; private: Registry(system_fsm::ServiceLocator&); system_fsm::ServiceLocator& services_; std::unique_ptr bridge_; std::shared_ptr ui_thread_; std::list> threads_; std::vector< std::pair>>>> modules_; }; } // namespace lua