summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-10-10 18:04:26 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-10-10 18:04:30 +0800
commit4ed5fddc914bf502d1729c8f184670763df577fc (patch)
tree853b28a803d414f89b9c217b9310d434e6610a40
parentb74ee5b5df3a65bd06571fe50b7f654a8782ad99 (diff)
downloadlua-language-server-4ed5fddc914bf502d1729c8f184670763df577fc.zip
update utility
-rw-r--r--script/utility.lua62
1 files changed, 36 insertions, 26 deletions
diff --git a/script/utility.lua b/script/utility.lua
index b383a171..936726f9 100644
--- a/script/utility.lua
+++ b/script/utility.lua
@@ -190,38 +190,48 @@ function m.dump(tbl, option)
end
--- 递归判断A与B是否相等
----@param a any
----@param b any
+---@param valueA any
+---@param valueB any
---@return boolean
-function m.equal(a, b)
- local tp1 = type(a)
- local tp2 = type(b)
- if tp1 ~= tp2 then
- return false
- end
- if tp1 == 'table' then
- local mark = {}
- for k, v in pairs(a) do
- mark[k] = true
- local res = m.equal(v, b[k])
- if not res then
- return false
- end
+function m.equal(valueA, valueB)
+ local hasChecked = {}
+
+ local function equal(a, b)
+ local tp1 = type(a)
+ local tp2 = type(b)
+ if tp1 ~= tp2 then
+ return false
end
- for k in pairs(b) do
- if not mark[k] then
- return false
+ if tp1 == 'table' then
+ if hasChecked[a] then
+ return true
+ end
+ hasChecked[a] = true
+ local mark = {}
+ for k, v in pairs(a) do
+ mark[k] = true
+ local res = equal(v, b[k])
+ if not res then
+ return false
+ end
+ end
+ for k in pairs(b) do
+ if not mark[k] then
+ return false
+ end
end
- end
- return true
- elseif tp1 == 'number' then
- if mathAbs(a - b) <= 1e-10 then
return true
+ elseif tp1 == 'number' then
+ if mathAbs(a - b) <= 1e-10 then
+ return true
+ end
+ return tostring(a) == tostring(b)
+ else
+ return a == b
end
- return tostring(a) == tostring(b)
- else
- return a == b
end
+
+ return equal(valueA, valueB)
end
local function sortTable(tbl)