mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
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:
@@ -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
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
elseif v == t2 then matched_values += 1 end
|
table.matches = table_matches
|
||||||
end
|
|
||||||
return matched_values == values
|
|
||||||
end
|
|
||||||
table.matches = matches
|
|
||||||
|
|
||||||
return table
|
return table
|
||||||
Reference in New Issue
Block a user