Skip to content
Damjan Adamic edited this page May 7, 2016 · 3 revisions

Welcome to the lua-reference-guide wiki!

How to edit/create Lua documentation

The OpenTX Lua interface documentation is written in a format that is compatible with https://www.gitbook.com where the document is also published https://www.gitbook.com/book/opentx/opentx-lua-reference-guide

There are two distinct parts to this documentation repository:

  • auto-generated content
  • manually generated content

Auto-generated content

Most of the documents here are generated with a special script that parses OpenTX source code, extracts Lua API documentation and outputs gitbook formated pages. The script also looks for any manually created pages that are included in each function documentation (examples, images, etc..).

Each page that is auto-generated has this comment at the begging to remind us not to edit it directly:

<!-- This file was generated by the script. Do not edit it, any changes will be lost! -->

In order to make changes to the contents of such page one has to:

  • edit the documentation in OpenTX code
  • edit manually created pages that are included in this page (examples, images, ...)

Architecture of auto-generated page

The base of each auto-generated page is a specially formated C comment that resides in one of the OpenTX source files. Each such comment documents one Lua API function. Here is example of playDuration() function description:

/*luadoc
@function playDuration(duration [, hourFormat])

Play a time value (text to speech)

@param duration (number) number of seconds to play. Only integral part is used.

@param hourFormat (number):
 * `0 or not present` play format: minutes and seconds.
 * `!= 0` play format: hours, minutes and seconds.

@status current Introduced in 2.1.0
*/

The auto-generated page will have the same name as the function in this example playDuration.md. The script also looks for and embeds any existing manually created pages/images that it finds:

  • <function_name>-example*.md is included verbatim
  • <function_name>-example*.png is included as image (linked)
  • <function_name>-example*.lua is included and rendered as Lua code example

This enables us to add additional content (such as examples) to the documentation of each function without polluting OpenTX source code with Lua examples and images.

Generation of auto-generated pages

The script that does this is https://github.com/opentx/lua-reference-guide/blob/master/tools/generate-api-docs.py.

TODO: how to run

Manually generated content

The rest of the pages are manually generated in a text editor or by some other method. The syntax is in Markdown language and can easily be edited with any text editor. WYSIWYG editor is also available on the github but the result (gitbook) can only be seen after the commit of the new text.

Recommended work-flow:

  • clone/pull this git repository
  • make changes
  • update auto-generated pages (if necessary)
  • generate gitbook locally and verify that the changes are good (TODO how to do this)
  • commit to local git repository
  • push the new commit to this repository or make a pull request

Clone this wiki locally