Преглед на файлове

Stabilise sorting order

Every time this was run it would generate a different init.lua since
the table.sort() function isn't a stable sort and hence keys that don't
exist in the priority table can (and do) get rearranged since they all
have equal priority.
bobsayshilol преди 2 години
родител
ревизия
c9781a6fed
променени са 2 файла, в които са добавени 1054 реда и са изтрити 862 реда
  1. 1043 861
      api/init.lua
  2. 11 1
      api/main.lua

Файловите разлики са ограничени, защото са твърде много
+ 1043 - 861
api/init.lua


+ 11 - 1
api/main.lua

@@ -363,7 +363,17 @@ function lovr.load()
     returns = 9
     returns = 9
   }
   }
   local function sort(keys, t)
   local function sort(keys, t)
-    table.sort(keys, function(a, b) return (keyPriority[a] or 1000) < (keyPriority[b] or 1000) end)
+    table.sort(keys, function(lhs, rhs)
+      local leftPrio = keyPriority[lhs]
+      local rightPrio = keyPriority[rhs]
+      if leftPrio and rightPrio then
+        return leftPrio < rightPrio
+      elseif leftPrio or rightPrio then
+        return leftPrio ~= nil
+      else
+        return lhs < rhs
+      end
+    end)
   end
   end
   local contents = 'return ' .. serpent.block(api, { comment = false, sortkeys = sort })
   local contents = 'return ' .. serpent.block(api, { comment = false, sortkeys = sort })
   file:write(contents)
   file:write(contents)

Някои файлове не бяха показани, защото твърде много файлове са промени