Simplify code of mainmenu world sort
authorNovatux <nathanael.courant@laposte.net>
Mon, 5 Aug 2013 16:49:19 +0000 (18:49 +0200)
committerPilzAdam <pilzadam@minetest.net>
Tue, 6 Aug 2013 16:33:23 +0000 (18:33 +0200)
builtin/filterlist.lua

index c9135d207cc4179d2ce3693f7d32c24df809c77d..906c339df3b7bd235b98d23735c8ee6edf9e2145 100644 (file)
@@ -239,18 +239,10 @@ end
 --------------------------------------------------------------------------------
 function sort_worlds_alphabetic(this) 
 
-       table.sort(this.m_processed_list, function(a, b) 
-                       local n1 = a.name 
-                       local n2 = b.name 
-                       local count = math.min(#n1, #n2) 
-                       
-                       for i=1,count do 
-                               if n1:sub(i, i):lower() < n2:sub(i, i):lower() then 
-                                       return true 
-                               elseif n1:sub(i, i):lower() > n2:sub(i, i):lower() then 
-                                       return false 
-                               end 
-                       end 
-                       return (#n1 <= #n2) 
-               end) 
+       table.sort(this.m_processed_list, function(a, b)
+               if a.name:lower() == b.name:lower() then
+                       return a.name < b.name
+               end
+               return a.name:lower() < b.name:lower()
+       end)
 end