From 0edb8d378faf9a99f57dabf6e2b7bf09dce2c339 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Sat, 2 Jan 2021 17:06:26 +0100 Subject: [PATCH] Add table.deep_to_add --- table.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/table.lua b/table.lua index 923cf4d..e8259ff 100644 --- a/table.lua +++ b/table.lua @@ -373,6 +373,18 @@ end 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) for key, value in pairs(additions) do table[key] = value