Microlight icon indicating copy to clipboard operation
Microlight copied to clipboard

Array:sort(f) requires a sort function to be given

Open mkottman opened this issue 12 years ago • 1 comments

Array:sort(f) in its current form requires a function to be given as the argument. When a simple comparison based on the < operator is sufficient, table.sort allows you to pass nil as the sort function to use the default sort order.

The following change allows you to use Array:sort() without an argument to use the default sort order, which is enough to sort arrays of strings and numbers.

--- /tmp/ml.lua 2013-09-01 20:25:53.940059979 +0200
+++ ml.lua  2013-09-01 20:34:31.800085274 +0200
@@ -919,7 +919,8 @@
     end

     function Array:sort(f)
-        table.sort(self,function_arg(f))
+        if type(f) ~= "nil" then f = function_arg(f) end
+        table.sort(self,f)
         return self
     end

mkottman avatar Sep 01 '13 18:09 mkottman

Thanks, Michal. These little details matter!

stevedonovan avatar Sep 02 '13 16:09 stevedonovan