aboutsummaryrefslogtreecommitdiffstats
path: root/util/array.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2020-09-30 09:50:33 +0100
committerMatthew Wild <mwild1@gmail.com>2020-09-30 09:50:33 +0100
commitbf6c2db68257e8ac3a35e2c4e7c18b55313a5bf7 (patch)
tree3a37db7b805b1555d08cc61c7938cf512ff35ce0 /util/array.lua
parent2940b9c66f4a053dbe2ca038468a3a8791beccd5 (diff)
parentbd3bd2179be360f86c7db3fcd400dbb168fa8be5 (diff)
downloadprosody-bf6c2db68257e8ac3a35e2c4e7c18b55313a5bf7.tar.gz
prosody-bf6c2db68257e8ac3a35e2c4e7c18b55313a5bf7.zip
Merge 0.11->trunk
Diffstat (limited to 'util/array.lua')
-rw-r--r--util/array.lua13
1 files changed, 11 insertions, 2 deletions
diff --git a/util/array.lua b/util/array.lua
index 0b60a4fd..6e5c8383 100644
--- a/util/array.lua
+++ b/util/array.lua
@@ -10,6 +10,7 @@ local t_insert, t_sort, t_remove, t_concat
= table.insert, table.sort, table.remove, table.concat;
local setmetatable = setmetatable;
+local getmetatable = getmetatable;
local math_random = math.random;
local math_floor = math.floor;
local pairs, ipairs = pairs, ipairs;
@@ -40,6 +41,10 @@ function array_mt.__add(a1, a2)
end
function array_mt.__eq(a, b)
+ if getmetatable(a) ~= array_mt or getmetatable(b) ~= array_mt then
+ -- Lua 5.3+ calls this if both operands are tables, even if metatables differ
+ return false;
+ end
if #a == #b then
for i = 1, #a do
if a[i] ~= b[i] then
@@ -129,9 +134,13 @@ function array_base.unique(outa, ina)
end);
end
-function array_base.pluck(outa, ina, key)
+function array_base.pluck(outa, ina, key, default)
for i = 1, #ina do
- outa[i] = ina[i][key];
+ local v = ina[i][key];
+ if v == nil then
+ v = default;
+ end
+ outa[i] = v;
end
return outa;
end