From 1573a8c4cde1cd9528b422b2dcc598e37ffe94a7 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 19:12:26 +1000 Subject: WIP merge cyclically dependent components into one big component --- src/tangara/lua/bridge.hpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/tangara/lua/bridge.hpp (limited to 'src/tangara/lua/bridge.hpp') diff --git a/src/tangara/lua/bridge.hpp b/src/tangara/lua/bridge.hpp new file mode 100644 index 00000000..64f14e0e --- /dev/null +++ b/src/tangara/lua/bridge.hpp @@ -0,0 +1,54 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include +#include + +#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>>&) + -> void; + + Bridge(const Bridge&) = delete; + Bridge& operator=(const Bridge&) = delete; + + private: + system_fsm::ServiceLocator& services_; + PropertyBindings bindings_; +}; + +} // namespace lua -- cgit v1.2.3