Software /
code /
prosody
Comparison
util/serialization.lua @ 9485:c667887d78ad
util.serialization: Simpler metatable pre-processing
It was too difficult to describe what it did.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Oct 2018 00:13:24 +0200 |
parent | 9484:1d1541630c20 |
child | 9486:20aad0108999 |
comparison
equal
deleted
inserted
replaced
9484:1d1541630c20 | 9485:c667887d78ad |
---|---|
137 o[l], l = fallback(t, "recursion"), l + 1; | 137 o[l], l = fallback(t, "recursion"), l + 1; |
138 return l; | 138 return l; |
139 end | 139 end |
140 | 140 |
141 o[t] = true; | 141 o[t] = true; |
142 if freeze then | 142 |
143 if freeze == true then | |
143 -- opportunity to do pre-serialization | 144 -- opportunity to do pre-serialization |
144 local mt = getmetatable(t); | 145 local mt = getmetatable(t); |
145 local fr = (type(freeze) == "table" and freeze[mt]); | 146 if type(mt) == "table" then |
146 local mf = mt and mt.__freeze; | 147 local tag = mt.__name; |
147 local tag; | 148 local fr = mt.__freeze; |
148 if type(fr) == "string" then | 149 |
149 tag = fr; | 150 if type(fr) == "function" then |
150 fr = mf; | 151 t = fr(t); |
151 elseif mt then | 152 if type(tag) == "string" then |
152 tag = mt.__type; | 153 o[l], l = tag, l + 1; |
153 end | 154 end |
154 if type(fr) == "function" then | |
155 t = fr(t); | |
156 if type(tag) == "string" then | |
157 o[l], l = tag, l + 1; | |
158 end | 155 end |
159 end | 156 end |
160 end | 157 end |
158 | |
161 o[l], l = tstart, l + 1; | 159 o[l], l = tstart, l + 1; |
162 local indent = s_rep(indentwith, d); | 160 local indent = s_rep(indentwith, d); |
163 local numkey = 1; | 161 local numkey = 1; |
164 local ktyp, vtyp; | 162 local ktyp, vtyp; |
165 for k,v in next,t do | 163 for k,v in next,t do |