Comparison

util/stanza.lua @ 7758:2b305ec8c146

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Fri, 02 Dec 2016 11:13:05 +0100
parent 7256:9fbb9fbf7e52
parent 7750:e58524240b30
child 8382:e5d00bf4a4d5
comparison
equal deleted inserted replaced
7747:0e442402cebc 7758:2b305ec8c146
12 local t_concat = table.concat; 12 local t_concat = table.concat;
13 local s_format = string.format; 13 local s_format = string.format;
14 local s_match = string.match; 14 local s_match = string.match;
15 local tostring = tostring; 15 local tostring = tostring;
16 local setmetatable = setmetatable; 16 local setmetatable = setmetatable;
17 local getmetatable = getmetatable;
17 local pairs = pairs; 18 local pairs = pairs;
18 local ipairs = ipairs; 19 local ipairs = ipairs;
19 local type = type; 20 local type = type;
20 local s_gsub = string.gsub; 21 local s_gsub = string.gsub;
21 local s_sub = string.sub; 22 local s_sub = string.sub;
41 stanza_mt.__index = stanza_mt; 42 stanza_mt.__index = stanza_mt;
42 43
43 local function new_stanza(name, attr, namespaces) 44 local function new_stanza(name, attr, namespaces)
44 local stanza = { name = name, attr = attr or {}, namespaces = namespaces, tags = {} }; 45 local stanza = { name = name, attr = attr or {}, namespaces = namespaces, tags = {} };
45 return setmetatable(stanza, stanza_mt); 46 return setmetatable(stanza, stanza_mt);
47 end
48
49 local function is_stanza(s)
50 return getmetatable(s) == stanza_mt;
46 end 51 end
47 52
48 function stanza_mt:query(xmlns) 53 function stanza_mt:query(xmlns)
49 return self:tag("query", { xmlns = xmlns }); 54 return self:tag("query", { xmlns = xmlns });
50 end 55 end
420 end 425 end
421 426
422 return { 427 return {
423 stanza_mt = stanza_mt; 428 stanza_mt = stanza_mt;
424 stanza = new_stanza; 429 stanza = new_stanza;
430 is_stanza = is_stanza;
425 new_id = new_id; 431 new_id = new_id;
426 preserialize = preserialize; 432 preserialize = preserialize;
427 deserialize = deserialize; 433 deserialize = deserialize;
428 clone = clone; 434 clone = clone;
429 message = message; 435 message = message;