aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-03-16 19:09:57 +0100
committerKim Alvefur <zash@zash.se>2017-03-16 19:09:57 +0100
commit91262e2bc848551822a25cad697d6d660dd5301e (patch)
tree063139fdddc4b690d2a9be43b7b8d818efba2719 /util
parent054f116c7dbe356666a312ab0ea19dfa03050999 (diff)
downloadprosody-91262e2bc848551822a25cad697d6d660dd5301e.tar.gz
prosody-91262e2bc848551822a25cad697d6d660dd5301e.zip
util.array: Add O(n) equality check metamethod
Diffstat (limited to 'util')
-rw-r--r--util/array.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/util/array.lua b/util/array.lua
index ea520f6b..05fa97ca 100644
--- a/util/array.lua
+++ b/util/array.lua
@@ -33,6 +33,19 @@ function array_mt.__add(a1, a2)
return res:append(a1):append(a2);
end
+function array_mt.__eq(a, b)
+ if #a == #b then
+ for i = 1, #a do
+ if a[i] ~= b[i] then
+ return false;
+ end
+ end
+ else
+ return false;
+ end
+ return true;
+end
+
setmetatable(array, { __call = new_array });
-- Read-only methods