load.lua 1.1 KB

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