aboutsummaryrefslogtreecommitdiff
path: root/utils.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-06-06 13:25:01 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-06-06 13:25:34 -0700
commit810ae220bc2b1dfa07593b77f391e4da3b57a6bb (patch)
treef5cdf811e673f4674097cb770b4f7d1fe932efe1 /utils.lua
parent2d88c68d712cb90f7e122465381899cd9f578e47 (diff)
Added list/dict metatables to make comparison and string representations
simpler. Also deleted Counters.
Diffstat (limited to 'utils.lua')
-rw-r--r--utils.lua15
1 files changed, 7 insertions, 8 deletions
diff --git a/utils.lua b/utils.lua
index c78a0c8..ac43757 100644
--- a/utils.lua
+++ b/utils.lua
@@ -241,30 +241,29 @@ local function sort(list, keyFn, reverse)
end
local function equivalent(x, y, depth)
- depth = depth or -1
- if x == y then
+ depth = depth or 0
+ if rawequal(x, y) then
return true
end
if type(x) ~= type(y) then
return false
end
- if type(x) ~= 'table' then
+ if type(x) ~= 'table' then return false end
+ if getmetatable(x) ~= getmetatable(y) then
return false
end
- if depth == 0 then
- return false
- elseif depth < -999 then
+ if depth >= 99 then
error("Exceeded maximum comparison depth")
end
local checked = {}
for k, v in pairs(x) do
- if not equivalent(y[k], v, depth - 1) then
+ if not equivalent(y[k], v, depth + 1) then
return false
end
checked[k] = true
end
for k, v in pairs(y) do
- if not checked[k] and not equivalent(x[k], v, depth - 1) then
+ if not checked[k] and not equivalent(x[k], v, depth + 1) then
return false
end
end