getFormat.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. return {
  2. tag = 'buffer-metadata',
  3. summary = 'Get the format of the Buffer.',
  4. description = 'Returns the format the Buffer was created with.',
  5. arguments = {},
  6. returns = {
  7. format = {
  8. type = 'table',
  9. description = 'A list of fields comprising the format.',
  10. table = {
  11. {
  12. name = '[].name',
  13. type = 'string',
  14. description = 'The name of the field (if fields were created with names).'
  15. },
  16. {
  17. name = '[].type',
  18. type = '*',
  19. description = 'The `DataType` of the field, or a recursive table with the sub-format.'
  20. },
  21. {
  22. name = '[].offset',
  23. type = 'number',
  24. description = 'The offset of the field relative to its parent, in bytes.'
  25. },
  26. {
  27. name = '[].length',
  28. type = 'number',
  29. description = 'The array length of the field, or `nil` if it\'s not an array.'
  30. },
  31. {
  32. name = '[].stride',
  33. type = 'number',
  34. description = 'The stride of the field in bytes, or `nil` if it\'s not an array.'
  35. }
  36. }
  37. }
  38. },
  39. variants = {
  40. {
  41. arguments = {},
  42. returns = { 'format' }
  43. }
  44. },
  45. example = [=[
  46. function lovr.load()
  47. buffer = lovr.graphics.newBuffer({
  48. { 'a', 'float' },
  49. { 'b', 'un16x2' }
  50. })
  51. for i, field in ipairs(buffer:getFormat()) do
  52. print(('%s: %s'):format(field.name, field.type))
  53. end
  54. -- prints the following:
  55. -- a: f32
  56. -- b: un16x2
  57. end
  58. ]=],
  59. related = {
  60. 'Buffer:getSize',
  61. 'Buffer:getLength',
  62. 'Buffer:getStride'
  63. }
  64. }