util/stanza.lua

changeset 1517
22be7637a64d
parent 1431
9fe9ba693f4a
child 1523
841d61be198f
equal deleted inserted replaced
1516:4c9bd0527d1d 1517:22be7637a64d
175 return s1:add_direct_child(s2); 175 return s1:add_direct_child(s2);
176 end 176 end
177 177
178 178
179 do 179 do
180 local id = 0; 180 local id = 0;
181 function new_id() 181 function new_id()
182 id = id + 1; 182 id = id + 1;
183 return "lx"..id; 183 return "lx"..id;
184 end 184 end
185 end 185 end
186 186
187 function preserialize(stanza) 187 function preserialize(stanza)
188 local s = { name = stanza.name, attr = stanza.attr }; 188 local s = { name = stanza.name, attr = stanza.attr };
189 for _, child in ipairs(stanza) do 189 for _, child in ipairs(stanza) do
224 224
225 return stanza; 225 return stanza;
226 end 226 end
227 227
228 function clone(stanza) 228 function clone(stanza)
229 local lookup_table = {}; 229 local lookup_table = {};
230 local function _copy(object) 230 local function _copy(object)
231 if type(object) ~= "table" then 231 if type(object) ~= "table" then
232 return object; 232 return object;
233 elseif lookup_table[object] then 233 elseif lookup_table[object] then
234 return lookup_table[object]; 234 return lookup_table[object];
235 end 235 end
236 local new_table = {}; 236 local new_table = {};
237 lookup_table[object] = new_table; 237 lookup_table[object] = new_table;
238 for index, value in pairs(object) do 238 for index, value in pairs(object) do
239 new_table[_copy(index)] = _copy(value); 239 new_table[_copy(index)] = _copy(value);
240 end 240 end
241 return setmetatable(new_table, getmetatable(object)); 241 return setmetatable(new_table, getmetatable(object));
242 end 242 end
243 return _copy(stanza) 243
244 return _copy(stanza)
244 end 245 end
245 246
246 function message(attr, body) 247 function message(attr, body)
247 if not body then 248 if not body then
248 return stanza("message", attr); 249 return stanza("message", attr);

mercurial