aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-03-26 13:07:20 +0200
committerKim Alvefur <zash@zash.se>2023-03-26 13:07:20 +0200
commit196117c3f23809393315df505dcd1d5c8b33b6dd (patch)
treeccd819820c54d86004063784995754d2da275b19
parent1a2fdf3f7f6d5ee4394e2e137717f8be8f1a3a20 (diff)
downloadprosody-196117c3f23809393315df505dcd1d5c8b33b6dd.tar.gz
prosody-196117c3f23809393315df505dcd1d5c8b33b6dd.zip
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.
-rw-r--r--util/set.lua9
1 files changed, 9 insertions, 0 deletions
diff --git a/util/set.lua b/util/set.lua
index 69dfef5d..a2704f6c 100644
--- a/util/set.lua
+++ b/util/set.lua
@@ -189,6 +189,15 @@ function set_mt.__tostring(set)
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;