title: Lua sort array by key values
body: <p>I've got an array of 32 elements set up like so:</p>
  
  <pre><code>racers[i] = {plCP = 0, plPos = 0}
  </code></pre>
  
  <p>I'd like to sort this array by the value plCP, and set plPos to be the value that the sort came up with. Something like this:</p>
  
  <pre><code>racers[1] = {plCP = 3, plPos = 3}
  racers[2] = {plCP = 2, plPos = 4}
  racers[3] = {plCP = 6, plPos = 2}
  racers[4] = {plCP = 12, plPos = 1}
  racers[4] = {plCP = 6, plPos = 2}
  </code></pre>
  
  <p>Also note that it is possible for 2 items to have the same plCP value. I'd like for them to have the same plPos value in these cases.</p>
  
  <p>This is for a racing game I'm working on, and I'm trying to calculate the position of the player in the race based upon which checkpoint they're currently driving towards.</p>