Software /
code /
prosody
Diff
util/array.lua @ 7976:2a7ef5fcaa77
util.array: Add O(n) equality check metamethod
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 16 Mar 2017 19:09:57 +0100 |
parent | 7700:0d70410efdcf |
child | 8017:ec7cab8e744d |
line wrap: on
line diff
--- a/util/array.lua Wed Mar 15 15:07:16 2017 +0100 +++ b/util/array.lua Thu Mar 16 19:09:57 2017 +0100 @@ -33,6 +33,19 @@ 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