aboutsummaryrefslogtreecommitdiffstats
path: root/util/stanza.lua
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2009-03-03 17:48:04 +0100
committerTobias Markmann <tm@ayena.de>2009-03-03 17:48:04 +0100
commit7a7a89844a038b071f02fd1af309ba9ebbcda7de (patch)
tree73946c977be10a965d59de85b3ce6ba3743bc771 /util/stanza.lua
parent3d1e7adbbc0afb8395f02ecd42fe3c38ce6a8d36 (diff)
parentb6b9906c3c653935b55ad79ad4a2c41118f0a0e3 (diff)
downloadprosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.tar.gz
prosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.zip
Merged with main tip.
Diffstat (limited to 'util/stanza.lua')
-rw-r--r--util/stanza.lua21
1 files changed, 20 insertions, 1 deletions
diff --git a/util/stanza.lua b/util/stanza.lua
index 1c1cab0e..5bc15609 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -12,9 +12,10 @@ local t_concat = table.concat;
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 @@ function deserialize(stanza)
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);