# HG changeset patch # User Kim Alvefur # Date 1539298316 -7200 # Node ID a96a2fbcc6c06d3baa5c2f7ac032142cd9ad1d1b # Parent 4e38121a349d915498f4ef76977b0296c152d1bd util.set: Add freeze metamethod diff -r 4e38121a349d -r a96a2fbcc6c0 util/set.lua --- 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 };