[0.16.19] Minor Bug in lualib util.merge
Posted: Fri Jan 26, 2018 2:25 pm
The current merge function has inconsistent copying behavior for table members, it will sometimes deepcopy and at other times reference-copy. I am using the function to copy prototypes and make adjustments, and my modifications were sometimes affecting the original prototypes too.
Code: Select all
function util.merge(tables)
local ret = {}
for i, tab in ipairs(tables) do
for k, v in pairs(tab) do
if (type(v) == "table") and (type(ret[k] or false) == "table") then
ret[k] = util.merge{ret[k], v}
-- Suggested addition start
elseif type(v) == "table" then
ret[k] = table.deepcopy(v)
-- Suggested addition end
else
ret[k] = v
end
end
end
return ret
end