run.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. return {
  2. tag = 'callbacks',
  3. summary = 'The main entry point.',
  4. description = [[
  5. This callback is the main entry point for a LÖVR program. It is responsible for calling
  6. `lovr.load` and returning the main loop function.
  7. ]],
  8. arguments = {},
  9. returns = {
  10. {
  11. name = 'loop',
  12. type = 'function',
  13. arguments = {},
  14. returns = {
  15. {
  16. name = 'result',
  17. type = '*'
  18. }
  19. },
  20. description = [[
  21. The main loop function. It should return nil to continue running, "restart" to restart the
  22. app, or a number representing an exit status.
  23. Most users should overload lovr.load, lovr.update and lovr.draw instead, since if a custom
  24. lovr.run does not do everything it is expected that some features may not work. For example,
  25. if lovr.run does not respond to "quit" events the program will not be able to quit, and if
  26. it does not call "present" then no graphics will be drawn.
  27. ]]
  28. }
  29. },
  30. example = {
  31. description = 'The default `lovr.run`:',
  32. code = [[
  33. function lovr.run()
  34. lovr.timer.step()
  35. if lovr.load then lovr.load() end
  36. return function()
  37. lovr.event.pump()
  38. for name, a, b, c, d in lovr.event.poll() do
  39. if name == 'quit' and (not lovr.quit or not lovr.quit()) then
  40. return a or 0
  41. end
  42. if lovr.handlers[name] then lovr.handlers[name](a, b, c, d) end
  43. end
  44. local dt = lovr.timer.step()
  45. if lovr.headset then
  46. lovr.headset.update(dt)
  47. end
  48. if lovr.audio then
  49. lovr.audio.update()
  50. if lovr.headset then
  51. lovr.audio.setOrientation(lovr.headset.getOrientation())
  52. lovr.audio.setPosition(lovr.headset.getPosition())
  53. lovr.audio.setVelocity(lovr.headset.getVelocity())
  54. end
  55. end
  56. if lovr.update then lovr.update(dt) end
  57. if lovr.graphics then
  58. lovr.graphics.origin()
  59. if lovr.draw then
  60. if lovr.headset then
  61. lovr.headset.renderTo(lovr.draw)
  62. end
  63. if lovr.graphics.hasWindow() then
  64. lovr.mirror()
  65. end
  66. end
  67. lovr.graphics.present()
  68. end
  69. lovr.math.drain()
  70. end
  71. end
  72. ]],
  73. },
  74. related = {
  75. 'lovr.load',
  76. 'lovr.quit'
  77. }
  78. }