3,804
edits
MusikAnimal (talk | contribs) (fix sorting) |
MusikAnimal (talk | contribs) (more fixes to sorting) |
||
Line 638: | Line 638: | ||
end | end | ||
table.sort(ret, function (t1, t2) | table.sort(ret, function (t1, t2) | ||
local int1, _suffix1 = | local num1 = t1.number | ||
local int2, _suffix2 = | local num2 = t2.number | ||
local int1, _suffix1 = num1:match('(%d+)(%a?)') | |||
local int2, _suffix2 = num2:match('(%d+)(%a?)') | |||
if tonumber(num1) ~= nil and tonumber(num2) ~= nil then | |||
return tonumber(num1) < tonumber(num2) | |||
elseif tonumber(num1) ~= nil and tonumber(num2) == nil then | |||
-- First is integer, second is string. | |||
return int1 == int2 | |||
elseif tonumber(num1) == nil and tonumber(num2) == nil then | |||
-- both are strings, hence should be compared as strings | |||
return num1 < num2 | |||
end | |||
return tonumber(int1) < tonumber(int2) | return tonumber(int1) < tonumber(int2) | ||
end) | end) |