util/stanza.lua

branch
s2s
changeset 145
fbb3a4ff9cf1
parent 91
6d66eb6b24cb
child 180
d8b9a19d70eb
equal deleted inserted replaced
144:ed78c1a0401e 145:fbb3a4ff9cf1
4 local tostring = tostring; 4 local tostring = tostring;
5 local setmetatable = setmetatable; 5 local setmetatable = setmetatable;
6 local pairs = pairs; 6 local pairs = pairs;
7 local ipairs = ipairs; 7 local ipairs = ipairs;
8 local type = type; 8 local type = type;
9 local next = next;
10 local print = print;
9 local unpack = unpack; 11 local unpack = unpack;
10 local s_gsub = string.gsub; 12 local s_gsub = string.gsub;
13
14 local debug = debug;
15 local log = require "util.logger".init("stanza");
16
11 module "stanza" 17 module "stanza"
12 18
13 stanza_mt = {}; 19 stanza_mt = {};
14 stanza_mt.__index = stanza_mt; 20 stanza_mt.__index = stanza_mt;
15 21
89 95
90 local attr_string = ""; 96 local attr_string = "";
91 if t.attr then 97 if t.attr then
92 for k, v in pairs(t.attr) do if type(k) == "string" then attr_string = attr_string .. s_format(" %s='%s'", k, tostring(v)); end end 98 for k, v in pairs(t.attr) do if type(k) == "string" then attr_string = attr_string .. s_format(" %s='%s'", k, tostring(v)); end end
93 end 99 end
94
95 return s_format("<%s%s>%s</%s>", t.name, attr_string, children_text, t.name); 100 return s_format("<%s%s>%s</%s>", t.name, attr_string, children_text, t.name);
96 end 101 end
97 102
98 function stanza_mt.__add(s1, s2) 103 function stanza_mt.__add(s1, s2)
99 return s1:add_child(s2); 104 return s1:add_child(s2);

mercurial