# HG changeset patch # User Kim Alvefur # Date 1679828840 -7200 # Node ID 895a82c5d8d47811cc430e25716ef51b013af58e # Parent c0e3e0d79574a7bd0561456a77a670b8fa48ea92 util.set: Add a serialization preparation metamethod Enables util.serialization to turn Sets into a representation that can be deserialized with an environment trick, i.e. `set{"a","b"}`. Also useful for debug purposes. diff -r c0e3e0d79574 -r 895a82c5d8d4 util/set.lua --- a/util/set.lua Sun Mar 26 00:49:25 2023 +0100 +++ b/util/set.lua Sun Mar 26 13:07:20 2023 +0200 @@ -189,6 +189,15 @@ return t_concat(s, ", "); end +function set_mt.__freeze(set) + local s = {}; + for item in pairs(set._items) do + s[#s + 1] = item; + end + return s; +end + + return { new = new; is_set = is_set;