Software /
code /
prosody
Changeset
9488:a96a2fbcc6c0
util.set: Add freeze metamethod
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Oct 2018 00:51:56 +0200 |
parents | 9487:4e38121a349d |
children | 9489:09b873ac7eb8 |
files | util/set.lua |
diffstat | 1 files changed, 8 insertions(+), 0 deletions(-) [+] |
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 };