summaryrefslogtreecommitdiff
path: root/src/config/lua/bindings
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2026-04-28 15:42:09 +0100
committerVaxry <43317083+vaxerski@users.noreply.github.com>2026-04-28 16:52:41 +0100
commitcbefb357a57ce5f6dd161a400a5867609022ee66 (patch)
tree446a9491200c0d495ab82562247d96b4e1af5b99 /src/config/lua/bindings
parent98fbbafef78057c818fb02b15c27e38ad2f5b5bc (diff)
desktop/windowRule: use variants for storage internally
Improves storage: less dynamic parsing, immediate config errors, faster.
Diffstat (limited to 'src/config/lua/bindings')
-rw-r--r--src/config/lua/bindings/LuaBindingsConfigRules.cpp22
-rw-r--r--src/config/lua/bindings/LuaBindingsInternal.cpp25
2 files changed, 34 insertions, 13 deletions
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<SP<Desktop::Rule::CWindowRule>, 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<SP<Desktop::Rule::CWindowRule>, 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);