From cd77265014a1ec51773c5cba92acb10670c829c0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 26 Oct 2008 14:27:10 +0000 Subject: Make add_child() behave as expected. Old add_child() is now add_direct_child() --- util/stanza.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/util/stanza.lua b/util/stanza.lua index 95a19fbd..bbd4776d 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -29,13 +29,13 @@ function stanza_mt:query(xmlns) 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 @@ function stanza_mt:up() 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 @@ function stanza_mt.__tostring(t) end function stanza_mt.__add(s1, s2) - return s1:add_child(s2); + return s1:add_direct_child(s2); end -- cgit v1.2.3