load.lua 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. return {
  2. summary = 'Load a file as Lua code.',
  3. description = 'Load a file containing Lua code, returning a Lua chunk that can be run.',
  4. arguments = {
  5. filename = {
  6. type = 'string',
  7. description = 'The file to load.'
  8. }
  9. },
  10. returns = {
  11. chunk = {
  12. type = 'function',
  13. arguments = {
  14. {
  15. name = '...',
  16. type = '*'
  17. }
  18. },
  19. returns = {
  20. {
  21. name = '...',
  22. type = '*'
  23. }
  24. },
  25. description = 'The runnable chunk.'
  26. }
  27. },
  28. variants = {
  29. {
  30. arguments = { 'filename' },
  31. returns = { 'chunk' }
  32. }
  33. },
  34. notes = 'An error is thrown if the file contains syntax errors.',
  35. example = {
  36. description = 'Safely loading code:',
  37. code = [[
  38. local success, chunk = pcall(lovr.filesystem.load, filename)
  39. if not success then
  40. print('Oh no! There was an error: ' .. tostring(chunk))
  41. else
  42. local success, result = pcall(chunk)
  43. print(success, result)
  44. end
  45. ]]
  46. }
  47. }