Add table.deep_to_add

This commit is contained in:
Lars Mueller 2021-01-02 17:06:26 +01:00
parent 04a33ca841
commit 0edb8d378f

@ -373,6 +373,18 @@ end
difference = to_add difference = to_add
function deep_to_add(table, after_additions)
local additions = {}
for key, value in pairs(after_additions) do
if type(table[key]) == "table" and type(value) == "table" then
additions[key] = deep_to_add(table[key], value)
elseif table[key] ~= value then
additions[key] = value
end
end
return additions
end
function add_all(table, additions) function add_all(table, additions)
for key, value in pairs(additions) do for key, value in pairs(additions) do
table[key] = value table[key] = value