aboutsummaryrefslogtreecommitdiffstats
path: root/util/set.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util/set.lua')
-rw-r--r--util/set.lua11
1 files changed, 10 insertions, 1 deletions
diff --git a/util/set.lua b/util/set.lua
index c136a522..02fabc6a 100644
--- a/util/set.lua
+++ b/util/set.lua
@@ -11,8 +11,9 @@ local ipairs, pairs, setmetatable, next, tostring =
local t_concat = table.concat;
local _ENV = nil;
+-- luacheck: std none
-local set_mt = {};
+local set_mt = { __name = "set" };
function set_mt.__call(set, _, k)
return next(set._items, k);
end
@@ -22,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 };