Software /
code /
prosody
Changeset
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 |
parents | 12985:c0e3e0d79574 |
children | 12987:2cf8d98d8a28 |
files | util/set.lua |
diffstat | 1 files changed, 9 insertions(+), 0 deletions(-) [+] |
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;