diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-08-16 11:50:49 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-08-16 11:50:49 +0100 |
commit | 1de15ba03e65cc106cdbb61402fc7282e45a1e14 (patch) | |
tree | 2c02c8c73c4333b84aeabe3e84ca7ce2515e9335 /lualib/lua_util.lua | |
parent | 6155385f69769bf04832ad3708849ab5cd054322 (diff) | |
download | rspamd-1de15ba03e65cc106cdbb61402fc7282e45a1e14.tar.gz rspamd-1de15ba03e65cc106cdbb61402fc7282e45a1e14.zip |
[Minor] Add support for transparent ucl in override_defaults
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r-- | lualib/lua_util.lua | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 650ad5db1..a64f8abc9 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -755,9 +755,29 @@ local function override_defaults(def, override) local res = {} - for k, v in pairs(override) do - if type(v) == 'table' then - if def[k] and type(def[k]) == 'table' then + -- Allow transparent ucl + local pairs_func, def_pairs_func = pairs, pairs + local type_func, def_type_func = type, type + if type(override[0]) == 'userdata' then + pairs_func = function(t) + return t:pairs() + end + type_func = function(t) + return t:type() + end + end + if type(def[0]) == 'userdata' then + def_pairs_func = function(t) + return t:pairs() + end + def_type_func = function(t) + return t:type() + end + end + + for k, v in pairs_func(override) do + if type_func(v) == 'table' then + if def[k] and def_type_func(def[k]) == 'table' then -- Recursively override elements res[k] = override_defaults(def[k], v) else @@ -768,7 +788,7 @@ local function override_defaults(def, override) end end - for k, v in pairs(def) do + for k, v in def_pairs_func(def) do if type(res[k]) == 'nil' then res[k] = v end |