2
0

lua.lua 844 B

123456789101112131415161718192021222324252627282930313233343536
  1. local serpent = require 'serpent'
  2. return function(api)
  3. local file = io.open(lovr.filesystem.getSource() .. '/init.lua', 'w')
  4. assert(file, 'Could not open init.lua for writing')
  5. local keyPriority = {
  6. name = 1,
  7. tag = 2,
  8. summary = 3,
  9. type = 4,
  10. description = 5,
  11. key = 6,
  12. module = 7,
  13. arguments = 8,
  14. returns = 9
  15. }
  16. local function sort(keys, t)
  17. table.sort(keys, function(lhs, rhs)
  18. local leftPrio = keyPriority[lhs]
  19. local rightPrio = keyPriority[rhs]
  20. if leftPrio and rightPrio then
  21. return leftPrio < rightPrio
  22. elseif leftPrio or rightPrio then
  23. return leftPrio ~= nil
  24. else
  25. return lhs < rhs
  26. end
  27. end)
  28. end
  29. local contents = 'return ' .. serpent.block(api, { comment = false, sortkeys = sort })
  30. file:write(contents)
  31. file:close()
  32. end