diff options
author | Kim Alvefur <zash@zash.se> | 2023-03-26 13:07:20 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2023-03-26 13:07:20 +0200 |
commit | 196117c3f23809393315df505dcd1d5c8b33b6dd (patch) | |
tree | ccd819820c54d86004063784995754d2da275b19 | |
parent | 1a2fdf3f7f6d5ee4394e2e137717f8be8f1a3a20 (diff) | |
download | prosody-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.lua | 9 |
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; |