Software /
code /
prosody
Changeset
9864:9d80e679c371
util.serialization: Allow overriding table iterator
Could be useful to eg swap it out with sorted_pairs to get a stable
serialization.
Default to next() wrapper to avoid metatable tricks from pairs().
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 17 Mar 2019 21:16:27 +0100 |
parents | 9863:aebfd1601ae2 |
children | 9865:37278b420c74 |
files | util/serialization.lua |
diffstat | 1 files changed, 6 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/util/serialization.lua Sun Mar 17 20:40:01 2019 +0100 +++ b/util/serialization.lua Sun Mar 17 21:16:27 2019 +0100 @@ -33,6 +33,10 @@ return (s_gsub(s, ".", char_to_hex)); end +local function rawpairs(t) + return next, t, nil; +end + local function fatal_error(obj, why) error("Can't serialize "..type(obj) .. (why and ": ".. why or "")); end @@ -122,6 +126,7 @@ local freeze = opt.freeze; local maxdepth = opt.maxdepth or 127; local multirefs = opt.multiref; + local table_pairs = opt.table_iterator or rawpairs; -- serialize one table, recursively -- t - table being serialized @@ -164,7 +169,7 @@ local numkey = 1; local ktyp, vtyp; local had_items = false; - for k,v in next,t do + for k,v in table_pairs(t) do had_items = true; o[l], l = itemstart, l + 1; o[l], l = indent, l + 1;