Browse Source

[Fix] Fix merge table utility

tags/3.7.1
Vsevolod Stakhov 10 months ago
parent
commit
b9fb73ce0b
No account linked to committer's email address
1 changed files with 15 additions and 2 deletions
  1. 15
    2
      lualib/lua_util.lua

+ 15
- 2
lualib/lua_util.lua View File

@@ -627,10 +627,23 @@ exports.table_cmp = table_cmp
-- Merge two tables
--]]
local function table_merge(t1, t2)
local res = {}
local nidx = 1 -- for numeric indicies
local it_func = function(k, v)
if type(k) == 'number' then
res[nidx] = v
nidx = nidx + 1
else
res[k] = v
end
end
for k, v in pairs(t1) do
it_func(k, v)
end
for k, v in pairs(t2) do
t1[k] = v
it_func(k, v)
end
return t1
return res
end

exports.table_merge = table_merge

Loading…
Cancel
Save