title: Sort a table of objects in Lua using one of its Classes
body: <p>I am trying to sort a table of objects in Lua, using one of its classes called <code>Name</code>.</p>
  
  <p>In Python you could do something like this:</p>
  
  <pre><code>sorted_table = sorted(objects, key=lambda x: x.Name)
  </code></pre>
  
  <p>What would be the elegant way of doing this in Lua?</p>
  
  <p>So far I have tried:</p>
  
  <pre><code>sorted_table = table.sort(objects, function(a,b) return a.name &lt; b.name end))
  </code></pre>
  
  <p>but it is giving me this error:</p>
  
  <pre><code>[string "table.sort(objects, function(a,b) re..."]:1: attempt to compare two nil values
  </code></pre>
  
  <p>when I dump the table it look like this:</p>
  
  <pre><code>table: 000000000AF9BE40
      1 = Polygon (0x00000000194A5250) [App: 'Fusion' on 127.0.0.1, UUID: f60e6d62-b100-42f3-b5d4-5799ccf86136]
      2 = Polygon (0x000000001956EC60) [App: 'Fusion' on 127.0.0.1, UUID: f60e6d62-b100-42f3-b5d4-5799ccf86136]
      3 = Polygon (0x000000001956FAF0) [App: 'Fusion' on 127.0.0.1, UUID: f60e6d62-b100-42f3-b5d4-5799ccf86136]
      4 = Polygon (0x0000000019570980) [App: 'Fusion' on 127.0.0.1, UUID: f60e6d62-b100-42f3-b5d4-5799ccf86136]
      5 = Polygon (0x00000000194A43C0) [App: 'Fusion' on 127.0.0.1, UUID: f60e6d62-b100-42f3-b5d4-5799ccf86136]
  </code></pre>
  
  <p>As an example, if I print the following:</p>
  
  <pre><code>print(object[1].Name)
  print(object[2].Name)
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Name0001
  Name0005
  </code></pre>
  
  <p>It is using these Names that I would like to sort my Table by</p>