From: Vsevolod Stakhov Date: Fri, 16 Aug 2024 10:50:49 +0000 (+0100) Subject: [Minor] Add support for transparent ucl in override_defaults X-Git-Tag: 3.10.0~37^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1de15ba03e65cc106cdbb61402fc7282e45a1e14;p=thirdparty%2Frspamd.git [Minor] Add support for transparent ucl in override_defaults --- diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 650ad5db1e..a64f8abc9a 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