aboutsummaryrefslogtreecommitdiffstats
path: root/util/set.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-10-12 00:51:56 +0200
committerKim Alvefur <zash@zash.se>2018-10-12 00:51:56 +0200
commit970307dbfb809e76cef3e32e29dbe363277f9c66 (patch)
tree509c766b49334916d7ff421a51c3f1d7bf9016f2 /util/set.lua
parent87f166a6be8553b33f1bccf396dfe50bc201c838 (diff)
downloadprosody-970307dbfb809e76cef3e32e29dbe363277f9c66.tar.gz
prosody-970307dbfb809e76cef3e32e29dbe363277f9c66.zip
util.set: Add freeze metamethod
Diffstat (limited to 'util/set.lua')
-rw-r--r--util/set.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/util/set.lua b/util/set.lua
index a4f20138..02fabc6a 100644
--- a/util/set.lua
+++ b/util/set.lua
@@ -23,6 +23,14 @@ function items_mt.__call(items, _, k)
return next(items, k);
end
+function set_mt:__freeze()
+ local a, i = {}, 1;
+ for item in self._items do
+ a[i], i = item, i+1;
+ end
+ return a;
+end
+
local function new(list)
local items = setmetatable({}, items_mt);
local set = { _items = items };