aboutsummaryrefslogtreecommitdiffstats
path: root/util/array.lua
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
commit0bf98e614f8ce41994280fabf07738c5c22404bf (patch)
tree063139fdddc4b690d2a9be43b7b8d818efba2719 /util/array.lua
parent911bea77466363a8bfcc01b1ebc689089d810efe (diff)
downloadprosody-0bf98e614f8ce41994280fabf07738c5c22404bf.tar.gz
prosody-0bf98e614f8ce41994280fabf07738c5c22404bf.zip
util.array: Add O(n) equality check metamethod
Diffstat (limited to 'util/array.lua')
-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