2021-11-13 08:31:32 +00:00
|
|
|
-- Copies [key, values] from src into dest, if they do not exist
|
|
|
|
function auMergeTable(dest, src)
|
|
|
|
auForEachKV(src, function(key, value)
|
|
|
|
if (dest[key]) then return end
|
|
|
|
dest[key] = value
|
|
|
|
end)
|
2021-11-16 13:05:03 +00:00
|
|
|
return dest
|
2021-11-13 08:31:32 +00:00
|
|
|
end
|
|
|
|
|
2021-11-21 17:23:31 +00:00
|
|
|
function auCopyTables(...)
|
|
|
|
local dest = {}
|
|
|
|
local args = table.pack(...)
|
|
|
|
for i=1, args.n do
|
|
|
|
local tbl = args[i]
|
2022-03-06 21:30:06 +00:00
|
|
|
if (tbl) then
|
|
|
|
auForEachKV(tbl, function(key, value) dest[key] = value end)
|
|
|
|
end
|
2021-11-21 17:23:31 +00:00
|
|
|
end
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2021-11-13 08:31:32 +00:00
|
|
|
-- Alternative to auConcatArrays
|
|
|
|
-- Copies src into dest
|
|
|
|
function auMergeArray(dest, src)
|
|
|
|
auForEach(src, function(value)
|
|
|
|
table.insert(dest, value)
|
|
|
|
end)
|
2021-11-16 13:05:03 +00:00
|
|
|
return dest
|
2022-03-06 21:30:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function table.copy(t)
|
|
|
|
local u = { }
|
|
|
|
for k, v in pairs(t) do u[k] = v end
|
|
|
|
--setmetatable(u, getmetatable(t))
|
|
|
|
return u
|
|
|
|
end
|
|
|
|
|
|
|
|
function auMap(array, func)
|
|
|
|
local tbl = {}
|
|
|
|
auForEach(array, function(value)
|
|
|
|
table.insert(tbl, func(value))
|
|
|
|
end)
|
|
|
|
return tbl
|
2021-11-13 08:31:32 +00:00
|
|
|
end
|