Software / code / prosody
Comparison
util/stanza.lua @ 7750:e58524240b30
util.stanza: Add an is_stanza() function to check if an object is a stanza
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 28 Nov 2016 07:30:21 +0100 |
| parent | 7253:f4e71242556a |
| child | 7758:2b305ec8c146 |
| child | 8998:6bddc90eeb27 |
comparison
equal
deleted
inserted
replaced
| 7749:a43a9ffd0579 | 7750:e58524240b30 |
|---|---|
| 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) | 44 local function new_stanza(name, attr) |
| 44 local stanza = { name = name, attr = attr or {}, tags = {} }; | 45 local stanza = { name = name, attr = attr or {}, 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 |
| 415 end | 420 end |
| 416 | 421 |
| 417 return { | 422 return { |
| 418 stanza_mt = stanza_mt; | 423 stanza_mt = stanza_mt; |
| 419 stanza = new_stanza; | 424 stanza = new_stanza; |
| 425 is_stanza = is_stanza; | |
| 420 new_id = new_id; | 426 new_id = new_id; |
| 421 preserialize = preserialize; | 427 preserialize = preserialize; |
| 422 deserialize = deserialize; | 428 deserialize = deserialize; |
| 423 clone = clone; | 429 clone = clone; |
| 424 message = message; | 430 message = message; |