Software /
code /
prosody
Diff
util/stanza.lua @ 862:b3b80ccddb0c
Merged with main tip.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Tue, 03 Mar 2009 17:48:04 +0100 |
parent | 829:b01fd698495e |
child | 896:2c0b9e3c11c3 |
line wrap: on
line diff
--- a/util/stanza.lua Sun Feb 22 20:57:57 2009 +0100 +++ b/util/stanza.lua Tue Mar 03 17:48:04 2009 +0100 @@ -12,9 +12,10 @@ local t_remove = table.remove; local t_concat = table.concat; local s_format = string.format; -local s_match = string.match; +local s_match = string.match; local tostring = tostring; local setmetatable = setmetatable; +local getmetatable = getmetatable; local pairs = pairs; local ipairs = ipairs; local type = type; @@ -215,6 +216,24 @@ return stanza; end +function clone(stanza) + local lookup_table = {}; + local function _copy(object) + if type(object) ~= "table" then + return object; + elseif lookup_table[object] then + return lookup_table[object]; + end + local new_table = {}; + lookup_table[object] = new_table; + for index, value in pairs(object) do + new_table[_copy(index)] = _copy(value); + end + return setmetatable(new_table, getmetatable(object)); + end + return _copy(stanza) +end + function message(attr, body) if not body then return stanza("message", attr);