I can't wrap my head around why record[x] would match up it's key name to a string in an array, then take it's value as the item to index the string by.. Is this some special feature of table.sort?
list = {"b", "c", "a"}
record = {a = 1, b = 2, c = 3}
table.sort(list, function (x, y) return record[x] < record[y] end)
for _, v in ipairs(list) do print(v) end
>a
>b
>c