tableMergeRecursiveArray
Definition
-- @/lua/common/utils.lua:665
-- merge tables and arrays correctly by concatenating arrays
function tableMergeRecursiveArray(t1, t2)
for k, v in pairs(t2) do
if type(v) == "table" and type(t1[k]) == "table" then
if tableIsArraySlow(t1[k]) and tableIsArraySlow(v) then
-- Concatenate arrays
for i = 1, #v do
table.insert(t1[k], v[i])
end
else
-- Merge associative tables recursively
tableMergeRecursiveArray(t1[k], v)
end
elseif type(v) == "table" then
-- Copy the table (array or associative)
if tableIsArraySlow(v) then
t1[k] = {}
for i = 1, #v do
t1[k][i] = v[i]
end
else
t1[k] = tableMergeRecursiveArray({}, v)
end
else
-- Overwrite or add the value
t1[k] = v
end
end
return t1
end
Callers
@/lua/common/jbeam/variables.lua
vehicle.components[k3] = vehicle.components[k3] or {}
tableMergeRecursiveArray( vehicle.components[k3], replaceTableKeysRecursive(v3, svars) )
else
@/lua/common/utils.lua
-- Merge associative tables recursively
tableMergeRecursiveArray(t1[k], v)
end
else
t1[k] = tableMergeRecursiveArray({}, v)
end
@/lua/vehicle/electrics.lua
--look at both the regular electrics data as well as the components version for deep merging
local jbeamData = tableMergeRecursiveArray(v.data.electrics or {}, v.data.components.electrics or {})