util.set: Add freeze metamethod

This commit is contained in:
Kim Alvefur 2018-10-12 00:51:56 +02:00
parent 15ba5f41b1
commit 1ab9729aac

View file

@ -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 };