update_documentation.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. local docroc = require 'tools/docroc'
  2. io.output('doc/README.md')
  3. for _, comment in ipairs(docroc.process('rx.lua')) do
  4. local tags = comment.tags
  5. if tags.class then
  6. io.write('# ' .. tags.class[1].name .. '\n\n')
  7. if tags.description then
  8. io.write(tags.description[1].text .. '\n\n')
  9. end
  10. else
  11. local context = comment.context:match('function.-([:%.].+)')
  12. if tags.arg then
  13. context = context:gsub('%b()', function(signature)
  14. local args = {}
  15. for _, arg in ipairs(tags.arg) do
  16. table.insert(args, arg.name)
  17. end
  18. return '(' .. table.concat(args, ', ') .. ')'
  19. end)
  20. end
  21. io.write(('---\n\n#### `%s`\n\n'):format(context))
  22. if tags.description then
  23. io.write(('%s\n\n'):format(tags.description[1].text))
  24. end
  25. if tags.arg then
  26. io.write('Arguments:\n\n')
  27. for _, arg in ipairs(tags.arg) do
  28. local name = arg.name
  29. if arg.optional then
  30. if arg.default then
  31. name = '[' .. name .. '=' .. arg.default .. ']'
  32. else
  33. name = '[' .. name .. ']'
  34. end
  35. end
  36. name = '`' .. name .. '`'
  37. local description = arg.description and (' - ' .. arg.description) or ''
  38. local type = ' (`' .. arg.type .. '`)'
  39. local line = '- ' .. name .. type .. description
  40. io.write(line .. '\n')
  41. end
  42. io.write('\n')
  43. end
  44. if tags.returns then
  45. io.write('Returns:\n\n')
  46. for _, result in ipairs(tags.returns) do
  47. io.write('- `' .. result.type .. '`\n')
  48. end
  49. io.write('\n')
  50. end
  51. end
  52. end