Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
12985:c0e3e0d79574 | 12986:895a82c5d8d4 |
---|---|
186 for item in pairs(items) do | 186 for item in pairs(items) do |
187 s[#s+1] = tostring(item); | 187 s[#s+1] = tostring(item); |
188 end | 188 end |
189 return t_concat(s, ", "); | 189 return t_concat(s, ", "); |
190 end | 190 end |
191 | |
192 function set_mt.__freeze(set) | |
193 local s = {}; | |
194 for item in pairs(set._items) do | |
195 s[#s + 1] = item; | |
196 end | |
197 return s; | |
198 end | |
199 | |
191 | 200 |
192 return { | 201 return { |
193 new = new; | 202 new = new; |
194 is_set = is_set; | 203 is_set = is_set; |
195 union = union; | 204 union = union; |