aboutsummaryrefslogtreecommitdiffstats
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
commit1ab9729aacb29265bd611c597f1b607d49e269a2 (patch)
tree509c766b49334916d7ff421a51c3f1d7bf9016f2
parent15ba5f41b17393bd610a547b3c62312986b9efc5 (diff)
downloadprosody-1ab9729aacb29265bd611c597f1b607d49e269a2.tar.gz
prosody-1ab9729aacb29265bd611c597f1b607d49e269a2.zip
util.set: Add freeze metamethod
-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 };