errhand.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. return {
  2. tag = 'callbacks',
  3. summary = 'Called when an error occurs.',
  4. description = [[
  5. The "lovr.errhand" callback is run whenever an error occurs. It receives two
  6. parameters. The first is a string containing the error message. The second is either
  7. nil, or a string containing a traceback (as returned by "debug.traceback()"); if nil,
  8. this means "lovr.errhand" is being called in the stack where the error occurred,
  9. and it can call "debug.traceback()" itself.
  10. "lovr.errhand" should return a handler function to run in a loop to show
  11. the error screen. This handler function is of the same type as the one returned by
  12. "lovr.run" and has the same requirements (such as pumping events). If an error occurs
  13. while this handler is running, the program will terminate immediately--
  14. "lovr.errhand" will not be given a second chance. Errors which occur inside "lovr.errhand"
  15. or in the handler it returns may not be cleanly reported, so be careful.
  16. A default error handler is supplied that renders the error message as text to the headset and
  17. to the window.
  18. ]],
  19. arguments = {
  20. {
  21. name = 'message',
  22. type = 'string',
  23. description = 'The error message.'
  24. },
  25. {
  26. name = 'traceback',
  27. type = 'string',
  28. description = 'A traceback string, or nil.'
  29. }
  30. },
  31. returns = {
  32. {
  33. name = 'handler',
  34. type = 'function',
  35. arguments = {},
  36. returns = {
  37. {
  38. name = 'result',
  39. type = '*'
  40. }
  41. },
  42. description = [[
  43. The error handler function. It should return nil to continue running, "restart" to restart the
  44. app, or a number representing an exit status.
  45. ]]
  46. }
  47. },
  48. example = [[
  49. function lovr.errhand(message, traceback)
  50. traceback = traceback or debug.traceback('', 3)
  51. print('ohh NOOOO!', message)
  52. print(traceback)
  53. return function()
  54. lovr.graphics.print('There was an error', 0, 2, -5)
  55. end
  56. end
  57. ]],
  58. related = {
  59. 'lovr.quit'
  60. }
  61. }