Changeset

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
parents 7749:a43a9ffd0579
children 7751:168919a947ed
files util/stanza.lua
diffstat 1 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/util/stanza.lua	Mon Nov 28 06:55:48 2016 +0100
+++ b/util/stanza.lua	Mon Nov 28 07:30:21 2016 +0100
@@ -14,6 +14,7 @@
 local s_match       =  string.match;
 local tostring      =      tostring;
 local setmetatable  =  setmetatable;
+local getmetatable  =  getmetatable;
 local pairs         =         pairs;
 local ipairs        =        ipairs;
 local type          =          type;
@@ -45,6 +46,10 @@
 	return setmetatable(stanza, stanza_mt);
 end
 
+local function is_stanza(s)
+	return getmetatable(s) == stanza_mt;
+end
+
 function stanza_mt:query(xmlns)
 	return self:tag("query", { xmlns = xmlns });
 end
@@ -417,6 +422,7 @@
 return {
 	stanza_mt = stanza_mt;
 	stanza = new_stanza;
+	is_stanza = is_stanza;
 	new_id = new_id;
 	preserialize = preserialize;
 	deserialize = deserialize;