Software /
code /
prosody
Diff
util/stanza.lua @ 180:d8b9a19d70eb
Make add_child() behave as expected. Old add_child() is now add_direct_child()
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 26 Oct 2008 14:27:10 +0000 |
parent | 145:fbb3a4ff9cf1 |
child | 181:d952eae776dc |
line wrap: on
line diff
--- a/util/stanza.lua Sun Oct 26 14:03:40 2008 +0000 +++ b/util/stanza.lua Sun Oct 26 14:27:10 2008 +0000 @@ -29,13 +29,13 @@ end function stanza_mt:tag(name, attrs) local s = stanza(name, attrs); - (self.last_add[#self.last_add] or self):add_child(s); + (self.last_add[#self.last_add] or self):add_direct_child(s); t_insert(self.last_add, s); return self; end function stanza_mt:text(text) - (self.last_add[#self.last_add] or self):add_child(text); + (self.last_add[#self.last_add] or self):add_direct_child(text); return self; end @@ -44,13 +44,19 @@ return self; end -function stanza_mt:add_child(child) +function stanza_mt:add_direct_child(child) if type(child) == "table" then t_insert(self.tags, child); end t_insert(self, child); end +function stanza_mt:add_child(child) + (self.last_add[#self.last_add] or self):add_direct_child(child); + t_insert(self.last_add, s); + return self; +end + function stanza_mt:child_with_name(name) for _, child in ipairs(self) do if child.name == name then return child; end @@ -101,7 +107,7 @@ end function stanza_mt.__add(s1, s2) - return s1:add_child(s2); + return s1:add_direct_child(s2); end