refactor(table): revert to old match function

Going to need some work to accurately compare some table types, but this is better for the intended purpose.
This commit is contained in:
Linden
2021-11-14 03:43:06 +11:00
parent a4c06746c5
commit 7c41ac5d6e

View File

@@ -26,28 +26,22 @@ local function contains(tbl, value)
end end
table.contains = contains table.contains = contains
local function matches(t1, t2) local function table_matches(t1, t2)
if t1 == t2 then return true end local type1, type2 = type(t1), type(t2)
if type(t1) ~= 'table' then return false end if type1 ~= type2 then return false end
if type1 ~= 'table' and type2 ~= 'table' then return t1 == t2 end
local matched_values = 0 for k1,v1 in pairs(t1) do
local values = 0 local v2 = t2[k1]
if v2 == nil or not table_matches(v1,v2) then return false end
end
for _, v in pairs(t1) do for k2,v2 in pairs(t2) do
values += 1 local v1 = t1[k2]
if type(t2) == 'table' then if v1 == nil or not table_matches(v1,v2) then return false end
for _, v2 in pairs(t2) do
if v == v2 then
matched_values += 1
elseif matches(v, v2) then
values += 1
matched_values += #v
end end
end return true
elseif v == t2 then matched_values += 1 end
end
return matched_values == values
end end
table.matches = matches table.matches = table_matches
return table return table