I’ve tried messing around with different functions to do this, but it’s melting my brain a little bit. Could anybody help out?
Here are some examples of what I am looking for.
local table1 = {
a = {
b = "testing!",
c = {
d = false,
}
}
}
local table2 = {
e = "hello world",
-- Having a nested table with the same key from both tables will combine the contents inside.
a = {
f = "hi"
}
}
local result = {
a = {
b = "testing!",
c = {
d = false,
},
--As you see, the there is also an a table in table2, so insert the f value inside of that to the nested table from table1.
f = "hi",
}
e = "hello world"
}
Current code I am working with.
function module.combine(tbl1: {any?}, tbl2: {any}): {any?}
local function recursive(tbl1, tbl2)
for key, value in pairs(tbl2) do
local to_change = value
if type(value) == "table" then
to_change = recursive({}, value)
end
tbl1[key] = to_change
end
return tbl1
end
local result = recursive(tbl1, tbl2)
return result
