Diff

util/set.lua @ 12986:895a82c5d8d4

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.
author Kim Alvefur <zash@zash.se>
date Sun, 26 Mar 2023 13:07:20 +0200
parent 11788:1ceee8becb1a
child 13033:a863e4237b91
line wrap: on
line diff
--- 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;