From 1681bea42dd2f11ba3fe6df05560d0b231de3c76 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Wed, 6 May 2026 13:56:12 +0100 Subject: config/lua: add simple layout API (#14258) Adds a simple layout lua api --- src/config/lua/ConfigManager.hpp | 65 +++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 28 deletions(-) (limited to 'src/config/lua/ConfigManager.hpp') diff --git a/src/config/lua/ConfigManager.hpp b/src/config/lua/ConfigManager.hpp index 77387758..4e670b23 100644 --- a/src/config/lua/ConfigManager.hpp +++ b/src/config/lua/ConfigManager.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "../../helpers/memory/Memory.hpp" #include "../ConfigManager.hpp" @@ -38,6 +39,10 @@ namespace Config::Lua { class CConfigManagerPluginLuaTestAccessor; } +namespace Config::Lua::Layouts { + struct SLuaLayoutProvider; +} + namespace Config::Lua::Bindings { void registerBindings(lua_State* L, CConfigManager* mgr); } @@ -87,6 +92,7 @@ namespace Config::Lua { void registerLuaRef(int ref); void callLuaFn(int ref); + std::expected registerLuaLayoutProvider(std::string name, lua_State* L, int providerTableIdx); // execute an arbitrary lua string on the current state. std::optional eval(const std::string& code); @@ -100,6 +106,7 @@ namespace Config::Lua { static constexpr int LUA_TIMEOUT_EVENT_CALLBACK_MS = 50; static constexpr int LUA_TIMEOUT_KEYBIND_CALLBACK_MS = 100; static constexpr int LUA_TIMEOUT_TIMER_CALLBACK_MS = 50; + static constexpr int LUA_TIMEOUT_LAYOUT_CALLBACK_MS = 50; static constexpr int LUA_TIMEOUT_EVAL_MS = 250; static constexpr int LUA_TIMEOUT_DISPATCH_MS = 100; @@ -136,34 +143,36 @@ namespace Config::Lua { std::unordered_map> m_luaLayerRules; private: - void reinitLuaState(); - void postConfigReload(); - void registerValue(const char* name, ILuaConfigValue* val); - void cleanTimers(); - void clearHeldLuaRefs(); - std::string luaConfigValueName(const std::string& s); - std::expected registerPluginLuaFunctionInState(uint64_t id, const std::string& namespace_, const std::string& name); - std::expected unregisterPluginLuaFunctionInState(const std::string& namespace_, const std::string& name); - void erasePluginLuaFunction(uint64_t id); - void reregisterLuaPluginFns(); - - static void watchdogHook(lua_State* L, lua_Debug* ar); - - lua_State* m_lua = nullptr; - - bool m_lastConfigVerificationWasSuccessful = true; - bool m_isFirstLaunch = true; - bool m_manualCrashInitiated = false; - bool m_watchdogActive = false; - bool m_isParsingConfig = false; - bool m_isEvaluating = false; - - std::chrono::steady_clock::time_point m_watchdogDeadline; - std::string m_watchdogContext; - - std::string m_mainConfigPath; - - std::vector m_heldLuaRefs; + void reinitLuaState(); + void postConfigReload(); + void registerValue(const char* name, ILuaConfigValue* val); + void cleanTimers(); + void clearLuaLayoutProviders(); + void clearHeldLuaRefs(); + std::string luaConfigValueName(const std::string& s); + std::expected registerPluginLuaFunctionInState(uint64_t id, const std::string& namespace_, const std::string& name); + std::expected unregisterPluginLuaFunctionInState(const std::string& namespace_, const std::string& name); + void erasePluginLuaFunction(uint64_t id); + void reregisterLuaPluginFns(); + + static void watchdogHook(lua_State* L, lua_Debug* ar); + + lua_State* m_lua = nullptr; + + bool m_lastConfigVerificationWasSuccessful = true; + bool m_isFirstLaunch = true; + bool m_manualCrashInitiated = false; + bool m_watchdogActive = false; + bool m_isParsingConfig = false; + bool m_isEvaluating = false; + + std::chrono::steady_clock::time_point m_watchdogDeadline; + std::string m_watchdogContext; + + std::string m_mainConfigPath; + + std::vector m_heldLuaRefs; + std::vector> m_luaLayoutProviders; // this is here for legacy reasons. std::unordered_map m_configPtrMap; -- cgit v1.2.3