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
commit9a6b45f887c1183e64dd77bc1c1e27c314ac26b1 (patch)
tree509c766b49334916d7ff421a51c3f1d7bf9016f2
parent8a5486f7fd02d522285b4a84626334e814130905 (diff)
downloadprosody-9a6b45f887c1183e64dd77bc1c1e27c314ac26b1.tar.gz
prosody-9a6b45f887c1183e64dd77bc1c1e27c314ac26b1.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 };