load.lua 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. {
  6. name = 'filename',
  7. type = 'string',
  8. description = 'The file to load.'
  9. }
  10. },
  11. returns = {
  12. {
  13. name = 'chunk',
  14. type = 'function',
  15. arguments = {
  16. {
  17. name = '...',
  18. type = '*'
  19. }
  20. },
  21. returns = {
  22. {
  23. name = '...',
  24. type = '*'
  25. }
  26. },
  27. description = 'The runnable chunk.'
  28. }
  29. },
  30. notes = 'An error is thrown if the file contains syntax errors.',
  31. example = {
  32. description = 'Safely loading code:',
  33. code = [[
  34. local success, chunk = pcall(lovr.filesystem.load, filename)
  35. if not success then
  36. print('Oh no! There was an error: ' .. tostring(chunk))
  37. else
  38. local success, result = pcall(chunk)
  39. print(success, result)
  40. end
  41. ]]
  42. }
  43. }