Comparison

util/stanza.lua @ 4936:92c86e11fd44

util.stanza: Make stanza:childtags() behave like :get_child()
author Kim Alvefur <zash@zash.se>
date Thu, 05 Jul 2012 17:58:47 +0200
parent 4749:b9de59ea8dad
child 5090:61c7c53c06d5
comparison
equal deleted inserted replaced
4935:bc62abceef07 4936:92c86e11fd44
131 return a[i]; 131 return a[i];
132 end, self, i; 132 end, self, i;
133 end 133 end
134 134
135 function stanza_mt:childtags(name, xmlns) 135 function stanza_mt:childtags(name, xmlns)
136 xmlns = xmlns or self.attr.xmlns;
137 local tags = self.tags; 136 local tags = self.tags;
138 local start_i, max_i = 1, #tags; 137 local start_i, max_i = 1, #tags;
139 return function () 138 return function ()
140 for i = start_i, max_i do 139 for i = start_i, max_i do
141 local v = tags[i]; 140 local v = tags[i];
142 if (not name or v.name == name) 141 if (not name or v.name == name)
143 and (not xmlns or xmlns == v.attr.xmlns) then 142 and ((not xmlns and self.attr.xmlns == v.attr.xmlns)
143 or v.attr.xmlns == xmlns) then
144 start_i = i+1; 144 start_i = i+1;
145 return v; 145 return v;
146 end 146 end
147 end 147 end
148 end; 148 end;