Module:Track listing: Difference between revisions

more fixes to sorting
(fix sorting)
(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 = t1.number:match('(%d+)(%a?)')
local num1 = t1.number
local int2, _suffix2 = t2.number:match('(%d+)(%a?)')
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)