aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-10-27 12:43:03 +0200
committerKim Alvefur <zash@zash.se>2018-10-27 12:43:03 +0200
commit669ab61ecdd06056995fbac2fbf7e5cc2ab5ee0e (patch)
treeb949b814294559492811672e610d7e8f75954a84 /util
parentf08a141337780d659564781bcbf7ff8ef381c209 (diff)
downloadprosody-669ab61ecdd06056995fbac2fbf7e5cc2ab5ee0e.tar.gz
prosody-669ab61ecdd06056995fbac2fbf7e5cc2ab5ee0e.zip
util.serialization: Add option for allowing multiple references to the same table (but not cycles)
Diffstat (limited to 'util')
-rw-r--r--util/serialization.lua10
1 files changed, 10 insertions, 0 deletions
diff --git a/util/serialization.lua b/util/serialization.lua
index 998b16de..a8b64c04 100644
--- a/util/serialization.lua
+++ b/util/serialization.lua
@@ -120,6 +120,7 @@ local function new(opt)
local hex = opt.hex;
local freeze = opt.freeze;
local maxdepth = opt.maxdepth or 127;
+ local multirefs = opt.multiref;
-- serialize one table, recursively
-- t - table being serialized
@@ -136,7 +137,10 @@ local function new(opt)
return l;
end
+ -- Keep track of table loops
+ local ot = t; -- reference pre-freeze
o[t] = true;
+ o[ot] = true;
if freeze == true then
-- opportunity to do pre-serialization
@@ -200,6 +204,12 @@ local function new(opt)
o[l], l = s_rep(indentwith, d-1), l + 1;
end
o[l], l = tend, l +1;
+
+ if multirefs then
+ o[t] = nil;
+ o[ot] = nil;
+ end
+
return l;
end