getString.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. return {
  2. summary = 'Get the Blob\'s contents as a string.',
  3. description = 'Returns a binary string containing the Blob\'s data.',
  4. arguments = {
  5. offset = {
  6. type = 'number',
  7. default = '0',
  8. description = 'A byte offset into the Blob where the string will start.'
  9. },
  10. size = {
  11. type = 'number',
  12. default = 'nil',
  13. description = [[
  14. The number of bytes the string will contain. If nil, the rest of the data in the Blob will
  15. be used, based on the `offset` parameter.
  16. ]]
  17. }
  18. },
  19. returns = {
  20. data = {
  21. type = 'string',
  22. description = 'The Blob\'s data.'
  23. }
  24. },
  25. variants = {
  26. {
  27. arguments = { 'offset', 'size' },
  28. returns = { 'data' }
  29. }
  30. },
  31. notes = [[
  32. This effectively allocates a new copy of the Blob as a Lua string, so this should be avoided for
  33. really big Blobs!
  34. ]],
  35. example = {
  36. description = 'Print each byte of the main.lua file:',
  37. code = [[
  38. blob = lovr.filesystem.newBlob('main.lua')
  39. str = blob:getString()
  40. for i = 1, #str do
  41. print(string.byte(str, i))
  42. end
  43. ]]
  44. }
  45. }