Software /
code /
prosody
Diff
util/set.lua @ 9488:a96a2fbcc6c0
util.set: Add freeze metamethod
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Oct 2018 00:51:56 +0200 |
parent | 8555:4f0f5b49bb03 |
child | 10594:13d5fb74648f |
child | 11542:c358537c0878 |
line wrap: on
line diff
--- a/util/set.lua Fri Oct 12 00:51:52 2018 +0200 +++ b/util/set.lua Fri Oct 12 00:51:56 2018 +0200 @@ -23,6 +23,14 @@ 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 };