Something like the following (untested code written in answer box) should work regardless of uniqueness (though lua table sorting isn't stable so you can't guarantee which of equal elements will be sorted first in case that matters):
local origtab = {4, 6, 2}
local sorttab = {}
for i,v in ipairs(origtab) do
sorttab[i] = {index = i, value = v}
end
table.sort(sorttab, function(a, b) return a.value < b.value end)
for i,t in ipairs(sorttab) do
-- t.index is original index
-- t.value is value
end