title: How do you copy a Lua table by value?
body: <p>Recently I wrote a bit of Lua code something like:</p>
  
  <pre><code>local a = {}
  for i = 1, n do
     local copy = a
     -- alter the values in the copy
  end
  </code></pre>
  
  <p>Obviously, that wasn't what I wanted to do since variables hold references to an anonymous table not the values of the table themselves in Lua.  This is clearly laid out in <a href="http://www.lua.org/pil/2.5.html" rel="noreferrer">Programming in Lua</a>, but I'd forgotten about it.</p>
  
  <p>So the question is what should I write instead of <code>copy = a</code> to get a copy of the values in <code>a</code>?</p>