Code: Select all
/c game.print(serpent.block(util.merge(
{
{
a = { aa = 5 }
},
{
a = { ab = 5 }
}
})));
-- expected: { a = { ab = 5 }}
-- actually: Cannot execute command. Error: data/core/lualib/util.lua:206: attempt to call global 'merge' (a nil value)
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] = merge{ret[k], v} --error message points to here
else
ret[k] = v
end
end
end
return ret
end
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}
else
ret[k] = v
end
end
end
return ret
end