title: How to join two tables (with subtables) in Lua
body: <p>I am trying to join two tables in Lua.  Basically, I want to append the contents of one table to the end of the other.  I've found lots of code to do this, but it doesn't work when the tables have other tables as values (subtables, I believe they are called?)</p>
  
  <p>I found this question to be similar:
  <a href="https://stackoverflow.com/questions/1283388/lua-merge-tables">Lua - merge tables?</a></p>
  
  <p>And the code there worked, other than the content in the second table is overwriting the first table.  But I do not want the entries in the first table to be overwritten.  I just want all the content in the second table to be appended after the content in the first.  But I can't figure out how to do that.</p>
  
  <p>So when my first table looks similar to this:</p>
  
  <pre><code>   { Category = 
        { Answer = "String",
          Answer = "String"
        }
     },
     { Category = 
        { Answer = "String",
          Answer = "String"
        }
     }
  </code></pre>
  
  <p>And my second is the same, I want to end up with:</p>
  
  <pre><code>   { Category = 
        { Answer = "String",
          Answer = "String"
        }
     },
     { Category = 
        { Answer = "String",
          Answer = "String"
        }
     },
     { Category = 
        { Answer = "String",
          Answer = "String"
        }
     },
     { Category = 
        { Answer = "String",
          Answer = "String"
        }
     }
  </code></pre>
  
  <p>How can this be accomplished?</p>
  
  <p>I am building these tables dynamically from XML files using this code:
  <a href="https://github.com/Cluain/Lua-Simple-XML-Parser" rel="nofollow noreferrer">https://github.com/Cluain/Lua-Simple-XML-Parser</a></p>
  
  <p>This is my XML file structure:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;library&gt;
      &lt;gametype1&gt;
          &lt;category name=""&gt;
              &lt;answer&gt;&lt;/answer&gt;
              &lt;answer&gt;&lt;/answer&gt;
              &lt;answer&gt;&lt;/answer&gt;
          &lt;/category&gt;
          &lt;category name=""&gt;
              &lt;answer&gt;&lt;/answer&gt;
              &lt;answer&gt;&lt;/answer&gt;
              &lt;answer&gt;&lt;/answer&gt;
          &lt;/category&gt;
      &lt;/gametype1&gt;
  
      &lt;gametype2&gt;
          &lt;category name=""&gt;
              &lt;answer&gt;&lt;/answer&gt;
              &lt;answer&gt;&lt;/answer&gt;
              &lt;answer&gt;&lt;/answer&gt;
          &lt;/category&gt;
          &lt;category name=""&gt;
              &lt;answer&gt;&lt;/answer&gt;
              &lt;answer&gt;&lt;/answer&gt;
              &lt;answer&gt;&lt;/answer&gt;
          &lt;/category&gt;
      &lt;/gametype2&gt;
  &lt;/library&gt;
  </code></pre>
  
  <p>I then load the XML files like such:</p>
  
  <pre><code>gameAnswers1 = xml:loadFile( "file1.xml", system.ResourceDirectory )
  gameAnswers2 = xml:loadFile( "file2.xml", system.ResourceDirectory )
  
  gameAnswers1Gametype1 = {}
  gameAnswers1Gametype1 = gameAnswers1.library.gametype1
  
  gameAnswers1Gametype2 = {}
  gameAnswers1Gametype2 = gameAnswers1.library.gametype2
  
  gameAnswers2Gametype1 = {}
  gameAnswers2Gametype1 = gameAnswers2.library.gametype1
  
  gameAnswers2Gametype2 = {}
  gameAnswers2Gametype2 = gameAnswers2.library.gametype2
  </code></pre>
  
  <p>What I would like to do now is concatenate the tables so that I have just one table of gametype1 data and one table of gametype2 data.</p>
  
  <p>And so when I access the table of data by <strong>#gameAnswers1Gametype1.category</strong> I get the correct number of entries.  With the current XML files I am using for testing, file1.xml has 9 category nodes in the gametype1 node and file2.xml has 1 category node in the gametype1 node.  So I would expect that when I am done, I will have 10 category nodes in the concatenated table.</p>
  
  <p>(If it matters, I am doing this with the Corona SDK.)</p>
  
  <p>Any help would be most appreciated!</p>