From 970307dbfb809e76cef3e32e29dbe363277f9c66 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 12 Oct 2018 00:51:56 +0200 Subject: util.set: Add freeze metamethod --- util/set.lua | 8 ++++++++ 1 file changed, 8 insertions(+) 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 }; -- cgit v1.2.3