Comparison

util/serialization.lua @ 9565:9a1e2f5f674f

util.serialization: Separate errors for multiple table references and max depth
author Kim Alvefur <zash@zash.se>
date Sat, 27 Oct 2018 12:38:47 +0200
parent 9564:ed0090f8b709
child 9567:dbfa286cfa88
comparison
equal deleted inserted replaced
9564:ed0090f8b709 9565:9a1e2f5f674f
126 -- o - array where tokens are added, concatenate to get final result 126 -- o - array where tokens are added, concatenate to get final result
127 -- - also used to detect cycles 127 -- - also used to detect cycles
128 -- l - position in o of where to insert next token 128 -- l - position in o of where to insert next token
129 -- d - depth, used for indentation 129 -- d - depth, used for indentation
130 local function serialize_table(t, o, l, d) 130 local function serialize_table(t, o, l, d)
131 if o[t] or d > maxdepth then 131 if o[t] then
132 o[l], l = fallback(t, "recursion"), l + 1; 132 o[l], l = fallback(t, "table has multiple references"), l + 1;
133 return l;
134 elseif d > maxdepth then
135 o[l], l = fallback(t, "max table depth reached"), l + 1;
133 return l; 136 return l;
134 end 137 end
135 138
136 o[t] = true; 139 o[t] = true;
137 140