util/stanza.lua

changeset 91
6d66eb6b24cb
parent 90
da468ed49a7b
child 145
fbb3a4ff9cf1
equal deleted inserted replaced
90:da468ed49a7b 91:6d66eb6b24cb
120 return s; 120 return s;
121 end 121 end
122 122
123 function deserialize(stanza) 123 function deserialize(stanza)
124 -- Set metatable 124 -- Set metatable
125 setmetatable(stanza, stanza_mt); 125 if stanza then
126 for _, child in ipairs(stanza) do 126 setmetatable(stanza, stanza_mt);
127 if type(child) == "table" then
128 deserialize(child);
129 end
130 end
131 if not stanza.tags then
132 -- Rebuild tags
133 local tags = {};
134 for _, child in ipairs(stanza) do 127 for _, child in ipairs(stanza) do
135 if type(child) == "table" then 128 if type(child) == "table" then
136 t_insert(tags, child); 129 deserialize(child);
137 end 130 end
138 end 131 end
139 stanza.tags = tags; 132 if not stanza.tags then
133 -- Rebuild tags
134 local tags = {};
135 for _, child in ipairs(stanza) do
136 if type(child) == "table" then
137 t_insert(tags, child);
138 end
139 end
140 stanza.tags = tags;
141 end
140 end 142 end
141 143
142 return stanza; 144 return stanza;
143 end 145 end
144 146

mercurial