I found a nice trick to sort an array of tables. Let's say I have an array like this:
ARR = [ {id ="example",val=10}, {id = "sort", val = 5}, {id = "routine", val = 15}, etc... ]
What I do is I generate an array of ARR.id string values, then append to each value a "000001","000002" etc. I sort the array using simple sort() function and then "extract" the rightmost number from the string, so I can repopulate the array of tables with the elements.
Let's say I want to sort the top array by "id", I create this array
TEMPARR = ["example000000","sort000001","routine000002"]
sort it
TEMPARR = ["example000000","routine000002","sort000001"]
and then extract the new "order" array: [0,2,1]. This is the order of the elements of the original array that will be regenerated.
This is not perfect, I'll have to put some null characters before the leading zeros to avoid the zeros to be part of the sorting, but overall it works and it's a bit faster than the array sorting with external function. It's more than twice as fast as squirrel sorting using @(a,b) a.id <=> b.id which is not bad at all.