diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-05-02 19:12:26 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-05-02 19:12:26 +1000 |
| commit | 1573a8c4cde1cd9528b422b2dcc598e37ffe94a7 (patch) | |
| tree | d162822b8fd7054f81bace0c7a65ab4d5e6f93ef /src/lua/include | |
| parent | a231fd1c8afedbeb14b0bc77d76bad61db986059 (diff) | |
| download | tangara-fw-1573a8c4cde1cd9528b422b2dcc598e37ffe94a7.tar.gz | |
WIP merge cyclically dependent components into one big component
Diffstat (limited to 'src/lua/include')
| -rw-r--r-- | src/lua/include/bridge.hpp | 54 | ||||
| -rw-r--r-- | src/lua/include/lua_controls.hpp | 15 | ||||
| -rw-r--r-- | src/lua/include/lua_database.hpp | 19 | ||||
| -rw-r--r-- | src/lua/include/lua_queue.hpp | 15 | ||||
| -rw-r--r-- | src/lua/include/lua_registry.hpp | 51 | ||||
| -rw-r--r-- | src/lua/include/lua_screen.hpp | 15 | ||||
| -rw-r--r-- | src/lua/include/lua_theme.hpp | 15 | ||||
| -rw-r--r-- | src/lua/include/lua_thread.hpp | 44 | ||||
| -rw-r--r-- | src/lua/include/lua_version.hpp | 15 | ||||
| -rw-r--r-- | src/lua/include/property.hpp | 107 |
10 files changed, 0 insertions, 350 deletions
diff --git a/src/lua/include/bridge.hpp b/src/lua/include/bridge.hpp deleted file mode 100644 index 64f14e0e..00000000 --- a/src/lua/include/bridge.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include <memory> -#include <string> - -#include "lua.hpp" -#include "lvgl.h" -#include "property.hpp" -#include "service_locator.hpp" - -namespace lua { - -/* - * Responsible for adding C/C++ module bindings to Lua threads. This class - * keeps no thread-specific internal state, and instead uses the LUA_REGISTRY - * table of its host threads to store data. - */ -class Bridge { - public: - /* - * Utility for retrieving the Bridge from a Lua thread in which the Bridge's - * bindings have been installed. Use by Lua's C callbacks to access the rest - * of the system. - */ - static auto Get(lua_State* state) -> Bridge*; - - Bridge(system_fsm::ServiceLocator& s); - - system_fsm::ServiceLocator& services() { return services_; } - - auto installBaseModules(lua_State* L) -> void; - auto installLvgl(lua_State* L) -> void; - auto installPropertyModule( - lua_State* L, - const std::string&, - std::vector< - std::pair<std::string, std::variant<LuaFunction, Property*>>>&) - -> void; - - Bridge(const Bridge&) = delete; - Bridge& operator=(const Bridge&) = delete; - - private: - system_fsm::ServiceLocator& services_; - PropertyBindings bindings_; -}; - -} // namespace lua diff --git a/src/lua/include/lua_controls.hpp b/src/lua/include/lua_controls.hpp deleted file mode 100644 index 18ad261d..00000000 --- a/src/lua/include/lua_controls.hpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include "lua.hpp" - -namespace lua { - -auto RegisterControlsModule(lua_State*) -> void; - -} // namespace lua diff --git a/src/lua/include/lua_database.hpp b/src/lua/include/lua_database.hpp deleted file mode 100644 index b0d2acbd..00000000 --- a/src/lua/include/lua_database.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include "lua.hpp" - -#include "database.hpp" - -namespace lua { - -auto db_check_iterator(lua_State*, int stack_pos) -> database::Iterator*; - -auto RegisterDatabaseModule(lua_State*) -> void; - -} // namespace lua diff --git a/src/lua/include/lua_queue.hpp b/src/lua/include/lua_queue.hpp deleted file mode 100644 index c5cfe04d..00000000 --- a/src/lua/include/lua_queue.hpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include "lua.hpp" - -namespace lua { - -auto RegisterQueueModule(lua_State*) -> void; - -} // namespace lua diff --git a/src/lua/include/lua_registry.hpp b/src/lua/include/lua_registry.hpp deleted file mode 100644 index abc5063e..00000000 --- a/src/lua/include/lua_registry.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include <memory> -#include <string> - -#include "lua.hpp" - -#include "bridge.hpp" -#include "lua_thread.hpp" -#include "service_locator.hpp" - -namespace lua { - -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 diff --git a/src/lua/include/lua_screen.hpp b/src/lua/include/lua_screen.hpp deleted file mode 100644 index 1c3bed1a..00000000 --- a/src/lua/include/lua_screen.hpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include "lua.hpp" - -namespace lua { - -auto RegisterScreenModule(lua_State*) -> void; - -} // namespace lua diff --git a/src/lua/include/lua_theme.hpp b/src/lua/include/lua_theme.hpp deleted file mode 100644 index fed710e0..00000000 --- a/src/lua/include/lua_theme.hpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2024 ailurux <ailuruxx@gmail.com> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include "lua.hpp" - -namespace lua { - -auto RegisterThemeModule(lua_State*) -> void; - -} // namespace lua diff --git a/src/lua/include/lua_thread.hpp b/src/lua/include/lua_thread.hpp deleted file mode 100644 index 384de61d..00000000 --- a/src/lua/include/lua_thread.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include <memory> -#include <string> - -#include "lua.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<Allocator>&, lua_State*); - - std::unique_ptr<Allocator> alloc_; - lua_State* state_; -}; - -} // namespace lua diff --git a/src/lua/include/lua_version.hpp b/src/lua/include/lua_version.hpp deleted file mode 100644 index 4ba4be94..00000000 --- a/src/lua/include/lua_version.hpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include "lua.hpp" - -namespace lua { - -auto RegisterVersionModule(lua_State*) -> void; - -} // namespace lua diff --git a/src/lua/include/property.hpp b/src/lua/include/property.hpp deleted file mode 100644 index 724261be..00000000 --- a/src/lua/include/property.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include <stdint.h> -#include <memory> -#include <string> - -#include "audio_events.hpp" -#include "bluetooth_types.hpp" -#include "lua.hpp" -#include "lvgl.h" -#include "service_locator.hpp" - -namespace lua { - -// FIXME: We should use some kind of interface for this instead. -using LuaValue = std::variant<std::monostate, - int, - bool, - std::string, - audio::TrackInfo, - drivers::bluetooth::Device, - std::vector<drivers::bluetooth::Device>>; - -using LuaFunction = std::function<int(lua_State*)>; - -class Property { - public: - Property() : Property(std::monostate{}) {} - Property(const LuaValue&); - Property(const LuaValue&, std::function<bool(const LuaValue&)> filter); - - auto get() -> const LuaValue& { return *value_; } - - /* - * Assigns a new value to this property, bypassing the filter fn. All - * bindings will be marked as dirty, and if active, will be reapplied. - */ - auto setDirect(const LuaValue&) -> void; - /* - * Invokes the filter fn, and if successful, assigns the new value to this - * property. All bindings will be marked as dirty, and if active, will be - * reapplied. - */ - auto set(const LuaValue&) -> bool; - - /* Returns whether or not this Property can be written from Lua. */ - auto isTwoWay() -> bool { return cb_.has_value(); } - - auto pushValue(lua_State& s) -> int; - auto popValue(lua_State& s) -> bool; - - /* Reapplies all active, dirty bindings associated with this Property. */ - auto reapplyAll() -> void; - - auto addLuaBinding(lua_State*, int ref) -> void; - auto applySingle(lua_State*, int ref, bool mark_dirty) -> bool; - - private: - std::unique_ptr<LuaValue> value_; - std::optional<std::function<bool(const LuaValue&)>> cb_; - std::pmr::vector<std::pair<lua_State*, int>> bindings_; -}; - -/* - * Container for a Lua function that should be invoked whenever a Property's - * value changes, as well as some extra accounting metadata. - */ -struct Binding { - /* Checks the value at idx is a Binding, returning a pointer to it if so. */ - static auto get(lua_State*, int idx) -> Binding*; - /* - * If the value at idx is a dirty, active Binding, applies the current value - * from its Property. Returns false if the binding was active and dirty, but - * invoking the Lua callback failed. - */ - static auto apply(lua_State*, int idx) -> bool; - - Property* property; - bool active; - bool dirty; -}; - -static_assert(std::is_trivially_destructible<Binding>()); -static_assert(std::is_trivially_copy_assignable<Binding>()); - -class PropertyBindings { - public: - PropertyBindings(); - - auto install(lua_State*) -> void; - - auto Register(lua_State*, Property*) -> void; - auto Register(lua_State*, LuaFunction) -> void; - - auto GetFunction(size_t i) -> const LuaFunction&; - - private: - std::pmr::vector<LuaFunction> functions_; -}; - -} // namespace lua |
