The Lua language
LuaDoc
Documentation Generator Tool for the Lua language

what is? · download · how to · subsections · options · news

What is LuaDoc?

LuaDoc is a documentation generator tool for Lua source code. Like JavaDoc, it parses the declarations and documentation comments in a set of Lua source files and produces a set of HTML pages describing the commented declarations and functions.

This new version (2.0) is entirely written in Lua. It requires Lua 4.0.

Download and Installation

LuaDoc can be freely downloaded by clicking here (which gives you a .tar.gz file).

To install LuaDoc, edit luadoc.lua to point to your Lua installation and set LUADOC_HOME variable to point to a directory where LuaDoc files will reside. Then, you may copy all files there.

On Unix boxes, the file luadoc.lua could be used as a script; it's the same as:

lua -f luadoc.lua [options|files]
This is the main script: it will load the other files and process the options. Try luadoc.lua --help: this will show you all available options.

How to comment

LuaDoc looks for the sequence of three minus signs (---). These sequence of characters indicate the beginning of a documented comment. The last period (.) before a function definition or an assignment will be considered the end of the documentation for the corresponding function or assignment. Inside this documentation, every part has to be ended with a period too.

The following code defines a function and its documentation.
--- Define special sequences of characters.
-- For each pair (find, subs), the function will create a field named with
-- find which has the value of subs.
-- It also creates an index for the table, according to the order of insertion.
-- @param subs The replacement pattern.
-- @param find The pattern to find.
function def_escapes (find, subs)
   local special = { t = "\t", n = "\n", ['"'] = '"', ['\\'] = '\\', }
   find = gsub (find, "\\(.)", function (x) return %special[x] or x end)
   subs = gsub (subs, "\\(.)", function (x) return %special[x] or x end)
   escape_sequences.n = escape_sequences.n+1
   escape_sequences[escape_sequences.n] = find
   escape_sequences[find] = subs
end
The first line (until the first period) will be the resume. The last two, which begins with -- @param, will compound the parameters section. The other lines will complete the description of the function. The corresponding documentation should be something like:
  • def_escapes (find, subs)
    Define special sequences of characters. For each pair (find, subs), the function will create a field named with find which has the value of subs. It also creates an index for the table, according to the order of insertion.
    Parameters:
    find: The pattern to find.
    subs: The replacement pattern.
  • A good example is the LuaDoc system itself. You can build the documentation by executing the following line from the LuaDoc directory:

    luadoc.lua *.lua
    
    It will produce one HTML file for each Lua file and the an index file. You can browse them here.

    Subsections

    LuaDoc can generate some subsections at each function or assignment documentation. Subsections are indicated at the source code with a `@' character followed by the name of the subsection:

    Command line options

    Version 2.0 has a different set of command line options. Here they are:

    News

    If you have tried LuaDoc, please mail us your suggestions:

    Last modification: Wed Aug 14 11:25:13 BRT 2002 by Tomás