From cbefb357a57ce5f6dd161a400a5867609022ee66 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 28 Apr 2026 15:42:09 +0100 Subject: desktop/windowRule: use variants for storage internally Improves storage: less dynamic parsing, immediate config errors, faster. --- src/config/lua/bindings/LuaBindingsConfigRules.cpp | 22 +++++++++++++------ src/config/lua/bindings/LuaBindingsInternal.cpp | 25 ++++++++++++++++------ 2 files changed, 34 insertions(+), 13 deletions(-) (limited to 'src/config/lua/bindings') diff --git a/src/config/lua/bindings/LuaBindingsConfigRules.cpp b/src/config/lua/bindings/LuaBindingsConfigRules.cpp index 2faab8c6..4f9fc861 100644 --- a/src/config/lua/bindings/LuaBindingsConfigRules.cpp +++ b/src/config/lua/bindings/LuaBindingsConfigRules.cpp @@ -1066,8 +1066,11 @@ static int hlWindowRule(lua_State* L) { auto val = Internal::ruleValueToString(L); if (!val) self->addError(std::format("{}: hl.window_rule: field '{}': {}", sourceInfo, key, val.error())); - else - rule->addEffect(*dynamicEffect, *val); + else { + auto res = rule->addEffect(*dynamicEffect, *val); + if (!res) + self->addError(std::format("{}: hl.window_rule: field '{}': {}", sourceInfo, key, res.error())); + } lua_pop(L, 1); continue; @@ -1077,12 +1080,17 @@ static int hlWindowRule(lua_State* L) { auto err = val->parse(L); if (err.errorCode != PARSE_ERROR_OK) { const bool allowLegacyString = (key == "max_size" || key == "min_size" || key == "border_color") && lua_isstring(L, -1); - if (allowLegacyString) - rule->addEffect(desc->effect, lua_tostring(L, -1)); - else + if (allowLegacyString) { + auto res = rule->addEffect(desc->effect, lua_tostring(L, -1)); + if (!res) + self->addError(std::format("{}: hl.window_rule: field '{}': {}", sourceInfo, key, res.error())); + } else self->addError(std::format("{}: hl.window_rule: field '{}': {}", sourceInfo, key, err.message)); - } else - rule->addEffect(desc->effect, val->toString()); + } else { + auto res = rule->addEffect(desc->effect, val->toString()); + if (!res) + self->addError(std::format("{}: hl.window_rule: field '{}': {}", sourceInfo, key, res.error())); + } lua_pop(L, 1); } diff --git a/src/config/lua/bindings/LuaBindingsInternal.cpp b/src/config/lua/bindings/LuaBindingsInternal.cpp index 02b7c060..e5a65bf7 100644 --- a/src/config/lua/bindings/LuaBindingsInternal.cpp +++ b/src/config/lua/bindings/LuaBindingsInternal.cpp @@ -527,7 +527,11 @@ std::expected, int> Internal::buildRuleFromTable( return std::unexpected(Internal::configError(L, "buildRuleFromTable: effect '{}': {}", key, val.error())); } - rule->addEffect(*dynamicEffect, *val); + auto res = rule->addEffect(*dynamicEffect, *val); + if (!res) { + lua_pop(L, 1); + return std::unexpected(Internal::configError(L, "buildRuleFromTable: effect '{}': {}", key, res.error())); + } hasRuleEffects = true; lua_pop(L, 1); @@ -538,14 +542,23 @@ std::expected, int> Internal::buildRuleFromTable( auto err = val->parse(L); if (err.errorCode != PARSE_ERROR_OK) { const bool allowLegacyString = (key == "max_size" || key == "min_size" || key == "border_color") && lua_isstring(L, -1); - if (allowLegacyString) - rule->addEffect(desc->effect, lua_tostring(L, -1)); - else { + if (allowLegacyString) { + auto res = rule->addEffect(desc->effect, lua_tostring(L, -1)); + if (!res) { + lua_pop(L, 1); + return std::unexpected(Internal::configError(L, "buildRuleFromTable: effect '{}': {}", key, res.error())); + } + } else { lua_pop(L, 1); return std::unexpected(Internal::configError(L, "buildRuleFromTable: effect '{}': {}", key, err.message)); } - } else - rule->addEffect(desc->effect, val->toString()); + } else { + auto res = rule->addEffect(desc->effect, val->toString()); + if (!res) { + lua_pop(L, 1); + return std::unexpected(Internal::configError(L, "buildRuleFromTable: effect '{}': {}", key, res.error())); + } + } hasRuleEffects = true; lua_pop(L, 1); -- cgit v1.2.3