# HG changeset patch # User Matthew Wild # Date 1620661316 -3600 # Node ID c358537c087858fc3b054976526452e054f74979 # Parent 13b84682518e6e754dca3c6ab626d9a140c33901 util.set: Add is_set() to test if an object is a set diff -r 13b84682518e -r c358537c0878 util/set.lua --- a/util/set.lua Mon May 10 16:24:54 2021 +0100 +++ b/util/set.lua Mon May 10 16:41:56 2021 +0100 @@ -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 @@ 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 @@ return { new = new; + is_set = is_set; union = union; difference = difference; intersection = intersection;