Quick way to sort a table by keys?

As part of the calculation for the x-twilio-signature (for confirming validity of an incoming Twilio POST), you have to sort all the POST variables, then append all the keys and values into one long string. For now, my quick-and-dirty way of doing this is:

`local bodyPOST = [];
local postString = “”

foreach(idx, val in http.urldecode(req.body)){
bodyPOST.append(idx + val);


foreach(postVariable in bodyPOST){
postString += postVariable;


Is there a way to sort the req.body table directly rather than copy it to an array?

Short answer: no. Longer answer: still no, a table is inherently an unsorted sequence (it gets some of its efficiency from the way it’s implemented in terms of Squirrel’s internal hashes of the keys). The Squirrel data structure that implements a sorted sequence is the array, so your code is as good as it’s going to get.


Good to know. Thanks!