mirror of
https://github.com/etlegacy/wolfadmin.git
synced 2024-11-24 21:21:56 +00:00
Fixed correct table merging by values
This commit is contained in:
parent
2d349919d0
commit
1a8e1f6af5
1 changed files with 19 additions and 0 deletions
|
@ -23,6 +23,25 @@ function tables.merge(tbl1, tbl2)
|
|||
util.typecheck("tables.merge", {tbl1}, {"table"})
|
||||
util.typecheck("tables.merge", {tbl2}, {"table"})
|
||||
|
||||
local exists = {}
|
||||
|
||||
for _, value in ipairs(tbl1) do
|
||||
exists[value] = true
|
||||
end
|
||||
|
||||
for _, value in ipairs(tbl2) do
|
||||
if not exists[value] then
|
||||
table.insert(tbl1, value)
|
||||
end
|
||||
end
|
||||
|
||||
return tbl1
|
||||
end
|
||||
|
||||
function tables.mergeKeys(tbl1, tbl2)
|
||||
util.typecheck("tables.mergeKeys", {tbl1}, {"table"})
|
||||
util.typecheck("tables.mergeKeys", {tbl2}, {"table"})
|
||||
|
||||
for key, value in pairs(tbl2) do
|
||||
tbl1[key] = value
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue