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); |