aboutsummaryrefslogtreecommitdiffstats
path: root/util/set.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2021-05-10 16:41:56 +0100
committerMatthew Wild <mwild1@gmail.com>2021-05-10 16:41:56 +0100
commit06161ab7662dace66ac7f33198d6ded5683d5abe (patch)
tree322d26e080f2e3b2598ad95e081693c96d0f1f5a /util/set.lua
parentf5460a5037f0dda1b02873ee189bf38685933529 (diff)
downloadprosody-06161ab7662dace66ac7f33198d6ded5683d5abe.tar.gz
prosody-06161ab7662dace66ac7f33198d6ded5683d5abe.zip
util.set: Add is_set() to test if an object is a set
Diffstat (limited to 'util/set.lua')
-rw-r--r--util/set.lua10
1 files changed, 8 insertions, 2 deletions
diff --git a/util/set.lua b/util/set.lua
index 02fabc6a..b7345e7e 100644
--- a/util/set.lua
+++ b/util/set.lua
@@ -6,8 +6,8 @@
-- COPYING file in the source package for more information.
--
-local ipairs, pairs, setmetatable, next, tostring =
- ipairs, pairs, setmetatable, next, tostring;
+local ipairs, pairs, getmetatable, setmetatable, next, tostring =
+ ipairs, pairs, getmetatable, setmetatable, next, tostring;
local t_concat = table.concat;
local _ENV = nil;
@@ -31,6 +31,11 @@ function set_mt:__freeze()
return a;
end
+local function is_set(o)
+ local mt = getmetatable(o);
+ return mt == set_mt;
+end
+
local function new(list)
local items = setmetatable({}, items_mt);
local set = { _items = items };
@@ -171,6 +176,7 @@ end
return {
new = new;
+ is_set = is_set;
union = union;
difference = difference;
intersection = intersection;