[0.16.19] Minor Bug in lualib util.merge

This subforum contains all the issues which we already resolved.
Post Reply
blueblue
Long Handed Inserter
Long Handed Inserter
Posts: 67
Joined: Tue Apr 11, 2017 7:39 pm
Contact:

[0.16.19] Minor Bug in lualib util.merge

Post by blueblue » 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

posila
Factorio Staff
Factorio Staff
Posts: 3936
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.16.19] Minor Bug in lualib util.merge

Post by posila » Mon Jan 29, 2018 4:18 pm

I though about it and concluded you are right. Implementation you proposed is more proper.

Thanks for the report.
Changed for 0.16.21

Post Reply

Return to “Resolved Problems and Bugs”

Who is online

Users browsing this forum: Bing [Bot]