Comparison

util/serialization.lua @ 9564:ed0090f8b709

util.serialization: Make maximum table depth configurable
author Kim Alvefur <zash@zash.se>
date Sat, 27 Oct 2018 12:17:35 +0200
parent 9486:20aad0108999
child 9565:9a1e2f5f674f
comparison
equal deleted inserted replaced
9563:732314eb3258 9564:ed0090f8b709
117 local kend = opt.kend or "]"; 117 local kend = opt.kend or "]";
118 local equals = opt.equals or " = "; 118 local equals = opt.equals or " = ";
119 local unquoted = opt.unquoted == nil and "^[%a_][%w_]*$" or opt.unquoted; 119 local unquoted = opt.unquoted == nil and "^[%a_][%w_]*$" or opt.unquoted;
120 local hex = opt.hex; 120 local hex = opt.hex;
121 local freeze = opt.freeze; 121 local freeze = opt.freeze;
122 local maxdepth = opt.maxdepth or 127;
122 123
123 -- serialize one table, recursively 124 -- serialize one table, recursively
124 -- t - table being serialized 125 -- t - table being serialized
125 -- o - array where tokens are added, concatenate to get final result 126 -- o - array where tokens are added, concatenate to get final result
126 -- - also used to detect cycles 127 -- - also used to detect cycles
127 -- l - position in o of where to insert next token 128 -- l - position in o of where to insert next token
128 -- d - depth, used for indentation 129 -- d - depth, used for indentation
129 local function serialize_table(t, o, l, d) 130 local function serialize_table(t, o, l, d)
130 if o[t] or d > 127 then 131 if o[t] or d > maxdepth then
131 o[l], l = fallback(t, "recursion"), l + 1; 132 o[l], l = fallback(t, "recursion"), l + 1;
132 return l; 133 return l;
133 end 134 end
134 135
135 o[t] = true; 136 o[t] = true;