├── .cvsignore ├── Makefile ├── Makefile.win ├── README.md ├── config ├── config.win ├── doc └── us │ ├── architecture.html │ ├── architecture.vsd │ ├── architecture_h.png │ ├── architecture_v.png │ ├── doc.css │ ├── email.png │ ├── examples.html │ ├── examples │ └── lfs │ │ └── lfs.luadoc │ ├── index.html │ ├── license.html │ ├── lua.png │ └── manual.html ├── rockspecs ├── luadoc-3.0.1-1.rockspec └── luadoc-cvs-1.rockspec ├── src ├── luadoc.bat ├── luadoc.lua.in └── luadoc │ ├── config.lua │ ├── doclet │ ├── debug.lua │ ├── formatter.lua │ ├── html.lua │ ├── html │ │ ├── file.lp │ │ ├── function.lp │ │ ├── index.lp │ │ ├── luadoc.css │ │ ├── menu.lp │ │ ├── module.lp │ │ └── table.lp │ └── raw.lua │ ├── init.lua │ ├── lp.lua │ ├── taglet │ ├── standard.lua │ └── standard │ │ └── tags.lua │ └── util.lua └── test └── trailing_hash_test.lua /.cvsignore: -------------------------------------------------------------------------------- 1 | .cproject 2 | .project 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.4 2008/02/17 06:42:51 jasonsantos Exp $ 2 | 3 | CONFIG= ./config 4 | 5 | include $(CONFIG) 6 | 7 | LUADOC_DIR= $(LUA_DIR)/luadoc 8 | DOCLET_DIR= $(LUADOC_DIR)/doclet 9 | HTML_DIR= $(DOCLET_DIR)/html 10 | TAGLET_DIR= $(LUADOC_DIR)/taglet 11 | STANDARD_DIR= $(TAGLET_DIR)/standard 12 | LUADOC_REFMAN= doc/refman 13 | 14 | LUADOC_LUAS= src/luadoc/config.lua \ 15 | src/luadoc/init.lua \ 16 | src/luadoc/lp.lua \ 17 | src/luadoc/util.lua 18 | DOCLET_LUAS= src/luadoc/doclet/debug.lua \ 19 | src/luadoc/doclet/formatter.lua \ 20 | src/luadoc/doclet/html.lua \ 21 | src/luadoc/doclet/raw.lua 22 | HTML_LUAS= src/luadoc/doclet/html/file.lp \ 23 | src/luadoc/doclet/html/function.lp \ 24 | src/luadoc/doclet/html/index.lp \ 25 | src/luadoc/doclet/html/luadoc.css \ 26 | src/luadoc/doclet/html/menu.lp \ 27 | src/luadoc/doclet/html/module.lp \ 28 | src/luadoc/doclet/html/table.lp 29 | TAGLET_LUAS= src/luadoc/taglet/standard.lua 30 | STANDARD_LUAS= src/luadoc/taglet/standard/tags.lua 31 | 32 | LAUNCHER= $(SYS_BINDIR)/luadoc 33 | LAUNCHER_SRC= src/luadoc.lua.in 34 | 35 | 36 | build clean: 37 | 38 | install: 39 | mkdir -p $(LUADOC_DIR) 40 | cp $(LUADOC_LUAS) $(LUADOC_DIR) 41 | mkdir -p $(DOCLET_DIR) 42 | cp $(DOCLET_LUAS) $(DOCLET_DIR) 43 | mkdir -p $(HTML_DIR) 44 | cp $(HTML_LUAS) $(HTML_DIR) 45 | mkdir -p $(TAGLET_DIR) 46 | cp $(TAGLET_LUAS) $(TAGLET_DIR) 47 | mkdir -p $(STANDARD_DIR) 48 | cp $(STANDARD_LUAS) $(STANDARD_DIR) 49 | mkdir -p $(SYS_BINDIR) 50 | cp $(LAUNCHER_SRC) $(LAUNCHER) 51 | chmod a+x $(LAUNCHER) 52 | 53 | refman: 54 | mkdir -p $(LUADOC_REFMAN) 55 | $(LAUNCHER) -d $(LUADOC_REFMAN) src/luadoc 56 | -------------------------------------------------------------------------------- /Makefile.win: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.win,v 1.3 2008/02/18 23:00:42 jasonsantos Exp $ 2 | 3 | include config.win 4 | 5 | LUADOC_DIR= $(LUA_DIR)\luadoc 6 | DOCLET_DIR= $(LUADOC_DIR)\doclet 7 | HTML_DIR= $(DOCLET_DIR)\html 8 | TAGLET_DIR= $(LUADOC_DIR)\taglet 9 | STANDARD_DIR= $(TAGLET_DIR)\standard 10 | LAUNCHER_DIR= c:\lua5.1 11 | LUADOC_REFMAN= doc\refman 12 | 13 | LUADOC_LUAS= src\luadoc\config.lua \ 14 | src\luadoc\init.lua \ 15 | src\luadoc\lp.lua \ 16 | src\luadoc\util.lua 17 | DOCLET_LUAS= src\luadoc\doclet\debug.lua \ 18 | src\luadoc\doclet\formatter.lua \ 19 | src\luadoc\doclet\html.lua \ 20 | src\luadoc\doclet\raw.lua 21 | HTML_LUAS= src\luadoc\doclet\html\file.lp \ 22 | src\luadoc\doclet\html\function.lp \ 23 | src\luadoc\doclet\html\index.lp \ 24 | src\luadoc\doclet\html\luadoc.css \ 25 | src\luadoc\doclet\html\menu.lp \ 26 | src\luadoc\doclet\html\module.lp \ 27 | src\luadoc\doclet\html\table.lp 28 | TAGLET_LUAS= src\luadoc\taglet\standard.lua 29 | STANDARD_LUAS= src\luadoc\taglet\standard\tags.lua 30 | 31 | LAUNCHER= src\luadoc.bat 32 | LAUNCHER_SRC= src\luadoc.lua.in 33 | LAUNCHER_START= luadoc_start.lua 34 | 35 | build clean: 36 | 37 | install: 38 | IF NOT EXIST "$(LUADOC_DIR)" mkdir "$(LUADOC_DIR)" 39 | FOR %F IN ($(LUADOC_LUAS)) DO copy "%F" "$(LUADOC_DIR)" 40 | IF NOT EXIST "$(DOCLET_DIR)" mkdir "$(DOCLET_DIR)" 41 | FOR %F IN ($(DOCLET_LUAS)) DO copy "%F" "$(DOCLET_DIR)" 42 | IF NOT EXIST "$(HTML_DIR)" mkdir "$(HTML_DIR)" 43 | FOR %F IN ($(HTML_LUAS)) DO copy "%F" "$(HTML_DIR)" 44 | IF NOT EXIST "$(TAGLET_DIR)" mkdir "$(TAGLET_DIR)" 45 | FOR %F IN ($(TAGLET_LUAS)) DO copy "%F" "$(TAGLET_DIR)" 46 | IF NOT EXIST "$(STANDARD_DIR)" mkdir "$(STANDARD_DIR)" 47 | FOR %F IN ($(STANDARD_LUAS)) DO copy "%F" "$(STANDARD_DIR)" 48 | IF NOT EXIST "$(LAUNCHER_DIR)" mkdir "$(LAUNCHER_DIR)" 49 | copy "$(LAUNCHER)" "$(LAUNCHER_DIR)" 50 | copy "$(LAUNCHER_SRC)" "$(LAUNCHER_DIR)\$(LAUNCHER_START)" 51 | 52 | 53 | 54 | refman: 55 | IF NOT EXIST "$(LUADOC_REFMAN)" mkdir "$(LUADOC_REFMAN)" 56 | "$(LAUNCHER)" -d "$(LUADOC_REFMAN)" src\luadoc 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **LuaDoc is obsolete, use [LDoc](https://github.com/stevedonovan/LDoc) instead.** 2 | 3 | LuaDoc, version 3.0 4 | Tomas Guisasola (tomas@tecgraf.puc-rio.br) 5 | http://luadoc.luaforge.net 6 | 13/aug/2007 7 | 8 | # What is it? 9 | 10 | LuaDoc is a documentation generator tool for Lua source code. 11 | It parses the declarations and documentation comments in a set of Lua 12 | source files and produces a set of XHTML pages describing the commented 13 | declarations and functions. 14 | 15 | The output is not limited to XHTML. Other formats can be generated by 16 | implementing new doclets. The format of the documentation comments is 17 | also flexible and can be customized by implementing new taglets. 18 | Please refer to customizing section for further information. 19 | 20 | LuaDoc is free software and uses the same license as Lua. 21 | 22 | # Distribution: 23 | 24 | This distribution includes a set of Lua files and this README. It 25 | requires Lua 5.1. 26 | 27 | # Installation: 28 | 29 | LuaDoc tool is composed by two parts, a library, and a launcher script. 30 | 31 | The library follows the package model for Lua 5.1, therefore it should 32 | be "installed". 33 | 34 | The launcher script, namely luadoc.lua for Unix and luadoc.bat for Windows, 35 | should be installed in your system PATH, so that it can be executed. 36 | 37 | LuaDoc also depends on two external packages: LuaFileSystem and LuaLogging, 38 | and you'll need to install them accordingly. 39 | 40 | On Unix boxes, the file luadoc.lua could be used as a script; 41 | it's the same as: 42 | 43 | lua5.1 luadoc.lua [options|files] 44 | 45 | This is the main script: it will load LuaDoc library and process the 46 | specified files. Try luadoc.lua --help, it will show you all available 47 | options. 48 | 49 | # How does it work? 50 | 51 | LuaDoc works in two phases: analysis and synthesis. On the first one, 52 | all input files are analyzed and an intermediate structure is made with 53 | this information. The second phase is responsible for cross-reference 54 | and the composition of the output. Each phase has an engine file and 55 | one or more description files, that describe the source format and the 56 | output format. This distribution only have a description of Lua source 57 | files and another for HTML output files. 58 | 59 | Some technical documentation can be built running LuaDoc over its 60 | files. 61 | 62 | Please send any comments and bug reports to tomas@tecgraf.puc-rio.br 63 | 64 | -------------------------------------------------------------------------------- /config: -------------------------------------------------------------------------------- 1 | # $Id: config,v 1.1 2008/02/17 06:42:51 jasonsantos Exp $ 2 | 3 | # Default installation prefix 4 | PREFIX=/usr/local 5 | 6 | # System's libraries directory (where binary libraries are installed) 7 | LUA_LIBDIR= $(PREFIX)/lib/lua/5.1 8 | 9 | # System's lua directory (where Lua libraries are installed) 10 | LUA_DIR= $(PREFIX)/share/lua/5.1 11 | 12 | # System's executables directory (where binary or script executables are installed) 13 | SYS_BINDIR= $(PREFIX)/bin 14 | 15 | # Complete path to Lua command line interpreter 16 | LUA_INTERPRETER= $(PREFIX)/bin/lua5.1 -------------------------------------------------------------------------------- /config.win: -------------------------------------------------------------------------------- 1 | # $Id: config.win,v 1.1 2008/02/17 06:42:51 jasonsantos Exp $ 2 | 3 | # System's libraries directory (where binary libraries are installed) 4 | LUA_LIBDIR= c:\lua5.1 5 | 6 | # System's lua directory (where Lua libraries are installed) 7 | LUA_DIR= c:\lua5.1\lua 8 | 9 | # System's executables directory (where binary or script executables are installed) 10 | SYS_BINDIR= c:\lua5.1 11 | 12 | # Complete path to Lua command line interpreter 13 | LUA_INTERPRETER= c:\lua5.1\lua5.1 14 | -------------------------------------------------------------------------------- /doc/us/architecture.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | LuaDoc: Documentation Generator Tool for the Lua language 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 |
14 | 17 |
LuaDoc
18 |
Documentation Generator Tool for the Lua language
19 |
20 | 21 |
22 | 23 | 64 | 65 |
66 |

Architecture

67 | 68 |

69 | LuaDoc's processing can be divided in two distinct steps: parsing and 70 | generation. The parsing step take as input a set of .lua files 71 | and must produce a Documentation object. A generator takes a 72 | Documentation object as input and produces a set of output files. 73 | It's up to the generator to decide which output format it will generate. 74 |

75 |

76 | The parsing step is executed by a component called 77 | taglet, while the generation is handled by a 78 | component called doclet. This architecture is 79 | shown below. 80 |

81 |

82 | Architecture 83 |

84 | 85 |

Taglet

86 |

87 | LuaDoc does not impose a documentation format. Instead, it relies on an internal 88 | representation of the documentation. This representation is described in the 89 | Documentation section. If the developer wants to 90 | use a custom documentation format the taglet component can be 91 | replaced. 92 |

93 |

94 | Writing a new taglet is a matter a implementing a single method: 95 |

96 |
 97 | function start (files, doc)
 98 | 
99 |
100 |
files
101 |
a list of file (or directory) names.
102 | 103 |
doc
104 |
a preprocessed documentation object.
105 |
106 | 107 |

108 | LuaDoc comes bundled with a standard taglet implementation. This implementation 109 | takes all file names in the list and produce the documentation object using a set 110 | of tags described in the section How To. If an 111 | item in the list is a directory it iterates recursively through all files in the 112 | directory looking for filenames with .lua or .luadoc 113 | extensions. 114 |

115 | 116 |

Documentation

117 |

118 | Instead of defining a documentation format LuaDoc defines an internal 119 | representation of a documentation object. Taglets and doclets must conform with 120 | this format. 121 |

122 |

123 | The documentation object is described below. Some description elements are explained 124 | below: 125 |

126 |
127 |
List
128 |
table indexed by number. Example: List<string> 129 | { 130 | [1] = "x", 131 | [2] = "y", 132 | [3] = "z", 133 | } 134 |
135 | 136 |
HashMap
137 |
table whose numerical indices are the key values for objects. Example: HashMap<string, string> 138 |
{
139 | 		[1] = "x",
140 | 		[2] = "y";
141 | 		[3] = "z";
142 | 		["x"] = "x coord",
143 | 		["y"] = "y coord",
144 | 		["z"] = "z coord",
145 | 	}
146 |
147 |
148 | 149 |

DOCUMENTATION

150 |
151 | {
152 | 	files = HashMap<string, DOCUMENTATION_ELEMENT>, -- indexed by file name
153 | 	modules = HashMap<string, DOCUMENTATION_ELEMENT>, -- indexed by module name
154 | }
155 | 
156 | 157 |

DOCUMENTATION_ELEMENT

158 |
159 | {
160 | 	type = ["file" | "module"],
161 | 	name = <string>, -- full path of file or name of module
162 | 	doc = List<BLOCK>, -- all documentation blocks
163 | 	functions = HashMap<string, BLOCK>, -- only functions, indexed by function name
164 | 	tables = HashMap<string, BLOCK>, -- only table definitions, indexed by table name
165 | 	},
166 | }
167 | 
168 | 169 |

BLOCK

170 |
171 | {
172 | 	class = ["module" | "function" | "table"],
173 | 	name = <string>,
174 | 	summary = <string>,
175 | 	description = <string>,
176 | 	comment = List<string>,
177 | 	code = List<string>,
178 | 	param = HashMap<string, string>,
179 | },
180 | 
181 | 182 |

Doclet

183 |

184 | The primary job of an doclet is to take a 185 | Documentation object and generate some kind of output. 186 | LuaDoc is bundled with an implementation that generates HTML files. 187 |

188 | 189 |

190 | Writing a new doclet is a matter a 191 | implementing a single method: 192 |

193 |
194 | function start (doc)
195 | 
196 |
197 |
doc
198 |
a documentation object.
199 |
200 | 201 | 202 |
203 | 204 |
205 | 206 |
207 |

Valid XHTML 1.0!

208 |

$Id: architecture.html,v 1.5 2007/08/13 15:32:45 carregal Exp $

209 |
210 | 211 |
212 | 213 | 214 | -------------------------------------------------------------------------------- /doc/us/architecture.vsd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keplerproject/luadoc/51577bf45502c0fb3ccabdef72fb20a549c63308/doc/us/architecture.vsd -------------------------------------------------------------------------------- /doc/us/architecture_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keplerproject/luadoc/51577bf45502c0fb3ccabdef72fb20a549c63308/doc/us/architecture_h.png -------------------------------------------------------------------------------- /doc/us/architecture_v.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keplerproject/luadoc/51577bf45502c0fb3ccabdef72fb20a549c63308/doc/us/architecture_v.png -------------------------------------------------------------------------------- /doc/us/doc.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin-left: 1em; 3 | margin-right: 1em; 4 | font-family: arial, helvetica, geneva, sans-serif; 5 | background-color:#ffffff; margin:0px; 6 | } 7 | 8 | code { 9 | font-family: "Andale Mono", monospace; 10 | } 11 | 12 | tt { 13 | font-family: "Andale Mono", monospace; 14 | } 15 | 16 | body, td, th { font-size: 11pt; } 17 | 18 | h1, h2, h3, h4 { margin-left: 0em; } 19 | 20 | textarea, pre, tt { font-size:10pt; } 21 | body, td, th { color:#000000; } 22 | small { font-size:0.85em; } 23 | h1 { font-size:1.5em; } 24 | h2 { font-size:1.25em; } 25 | h3 { font-size:1.15em; } 26 | h4 { font-size:1.06em; } 27 | 28 | a:link { font-weight:bold; color: #004080; text-decoration: none; } 29 | a:visited { font-weight:bold; color: #006699; text-decoration: none; } 30 | a:link:hover { text-decoration:underline; } 31 | hr { color:#cccccc } 32 | img { border-width: 0px; } 33 | 34 | h3 { padding-top: 1em; } 35 | 36 | p { margin-left: 1em; } 37 | 38 | p.name { 39 | font-family: "Andale Mono", monospace; 40 | padding-top: 1em; 41 | margin-left: 0em; 42 | } 43 | 44 | blockquote { margin-left: 3em; } 45 | 46 | .example { 47 | background-color: rgb(245, 245, 245); 48 | border-top-width: 1px; 49 | border-right-width: 1px; 50 | border-bottom-width: 1px; 51 | border-left-width: 1px; 52 | border-top-style: solid; 53 | border-right-style: solid; 54 | border-bottom-style: solid; 55 | border-left-style: solid; 56 | border-top-color: silver; 57 | border-right-color: silver; 58 | border-bottom-color: silver; 59 | border-left-color: silver; 60 | padding: 1em; 61 | margin-left: 1em; 62 | margin-right: 1em; 63 | font-family: "Andale Mono", monospace; 64 | font-size: smaller; 65 | } 66 | 67 | hr { 68 | margin-left: 0em; 69 | background: #00007f; 70 | border: 0px; 71 | height: 1px; 72 | } 73 | 74 | ul { list-style-type: disc; } 75 | 76 | table.index { border: 1px #00007f; } 77 | table.index td { text-align: left; vertical-align: top; } 78 | table.index ul { padding-top: 0em; margin-top: 0em; } 79 | 80 | table { 81 | border: 1px solid black; 82 | border-collapse: collapse; 83 | margin-left: auto; 84 | margin-right: auto; 85 | } 86 | 87 | th { 88 | border: 1px solid black; 89 | padding: 0.5em; 90 | } 91 | 92 | td { 93 | border: 1px solid black; 94 | padding: 0.5em; 95 | } 96 | div.header, div.footer { margin-left: 0em; } 97 | 98 | #container { 99 | margin-left: 1em; 100 | margin-right: 1em; 101 | background-color: #f0f0f0; 102 | } 103 | 104 | #product { 105 | text-align: center; 106 | border-bottom: 1px solid #cccccc; 107 | background-color: #ffffff; 108 | } 109 | 110 | #product big { 111 | font-size: 2em; 112 | } 113 | 114 | #product_logo { 115 | } 116 | 117 | #product_name { 118 | } 119 | 120 | #product_description { 121 | } 122 | 123 | #main { 124 | background-color: #f0f0f0; 125 | border-left: 2px solid #cccccc; 126 | } 127 | 128 | #navigation { 129 | float: left; 130 | width: 12em; 131 | margin: 0; 132 | vertical-align: top; 133 | background-color: #f0f0f0; 134 | overflow:visible; 135 | } 136 | 137 | #navigation h1 { 138 | background-color:#e7e7e7; 139 | font-size:1.1em; 140 | color:#000000; 141 | text-align:left; 142 | margin:0px; 143 | padding:0.2em; 144 | border-top:1px solid #dddddd; 145 | border-bottom:1px solid #dddddd; 146 | } 147 | 148 | #navigation ul { 149 | font-size:1em; 150 | list-style-type: none; 151 | padding: 0; 152 | margin: 1px; 153 | } 154 | 155 | #navigation li { 156 | text-indent: -1em; 157 | margin: 0em 0em 0em 0.5em; 158 | display: block; 159 | padding: 3px 0px 0px 12px; 160 | } 161 | 162 | #navigation li li a { 163 | padding: 0px 3px 0px -1em; 164 | } 165 | 166 | #content { 167 | margin-left: 12em; 168 | padding: 1em; 169 | border-left: 2px solid #cccccc; 170 | border-right: 2px solid #cccccc; 171 | background-color: #ffffff; 172 | } 173 | 174 | #about { 175 | clear: both; 176 | margin: 0; 177 | padding: 5px; 178 | border-top: 2px solid #cccccc; 179 | background-color: #ffffff; 180 | } 181 | 182 | @media print { 183 | body { 184 | font: 10pt "Times New Roman", "TimeNR", Times, serif; 185 | } 186 | a { 187 | font-weight:bold; color: #004080; text-decoration: underline; 188 | } 189 | #main { 190 | background-color: #ffffff; border-left: 0px; 191 | } 192 | #container { 193 | margin-left: 2%; margin-right: 2%; background-color: #ffffff; 194 | } 195 | #content { 196 | margin-left: 0px; padding: 1em; border-left: 0px; border-right: 0px; background-color: #ffffff; 197 | } 198 | #navigation { 199 | display: none; 200 | } 201 | #product_logo { 202 | display: none; 203 | } 204 | #about img { 205 | display: none; 206 | } 207 | .example { 208 | font-family: "Andale Mono", monospace; 209 | font-size: 8pt; 210 | page-break-inside: avoid; 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /doc/us/email.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keplerproject/luadoc/51577bf45502c0fb3ccabdef72fb20a549c63308/doc/us/email.png -------------------------------------------------------------------------------- /doc/us/examples.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | LuaDoc: Documentation Generator Tool for the Lua language 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 |
14 | 17 |
LuaDoc
18 |
Documentation Generator Tool for the Lua language
19 |
20 | 21 |
22 | 23 | 64 | 65 |
66 |

Examples

67 | 68 |

69 | A documentation example is LuaDoc own source code and the generated documentation. 70 | The source code can be browsed from the 71 | CVS repository. The generated 72 | documentation can be browsed online. 73 |

74 | 75 |

76 | You can also document a Lua library which is written in C. To do that simply write a file 77 | with the .luadoc extension and define the function prototypes with 78 | the documentation comments. This file will be parsed by LuaDoc and the documentation 79 | will be generated. 80 |

81 | 82 |

83 | As an example the LuaFileSystem 84 | API was defined in a file called lfs.luadoc. 85 | The generated documentation can be browsed online. 86 |

87 | 88 |

89 |


















90 |

91 | 92 |
93 | 94 |
95 | 96 |
97 |

Valid XHTML 1.0!

98 |

$Id: examples.html,v 1.3 2007/08/13 15:32:45 carregal Exp $

99 |
100 | 101 |
102 | 103 | 104 | -------------------------------------------------------------------------------- /doc/us/examples/lfs/lfs.luadoc: -------------------------------------------------------------------------------- 1 | 2 | --- LuaFileSystem is a Lua library developed to complement the set of functions 3 | -- related to file systems offered by the standard Lua distribution. 4 | -- LuaFileSystem offers a portable way to access the underlying directory 5 | -- structure and file attributes. 6 | 7 | module "lfs" 8 | 9 | --- Returns a table with the file attributes corresponding to 10 | -- filepath (or nil followed by an error message 11 | -- in case of error). 12 | -- If the second optional argument is given, then only the value of the 13 | -- named attribute is returned (this use is equivalent to 14 | -- lfs.attributes(filepath).aname, but the table is not created 15 | -- and only one attribute is retrieved from the O.S.). 16 | -- The attributes are described as follows; 17 | -- attribute mode is a string, all the others are numbers, 18 | -- and the time related attributes use the same time reference of 19 | -- os.time. 20 | function attributes (filepath, aname) 21 | 22 | --- Changes the current working directory to the given 23 | -- path.
24 | -- Returns true in case of success or nil plus an 25 | -- error string. 26 | function chdir (path) 27 | 28 | --- Returns a string with the current working directory or nil 29 | -- plus an error string. 30 | function currentdir () 31 | 32 | --- Lua iterator over the entries of a given directory. 33 | -- Each time the iterator is called it returns a string with an entry of the 34 | -- directory; nil is returned when there is no more entries. 35 | -- Raises an error if path is not a directory. 36 | function dir (path) 37 | 38 | --- Locks a file or a part of it. This function works on open files; the 39 | -- file handle should be specified as the first argument. 40 | -- The string mode could be either 41 | -- r (for a read/shared lock) or w (for a 42 | -- write/exclusive lock). The optional arguments start 43 | -- and length can be used to specify a starting point and 44 | -- its length; both should be numbers.
45 | -- Returns true if the operation was successful; in 46 | -- case of error, it returns nil plus an error string. 47 | function lock (filehandle, mode, start, length) 48 | 49 | --- Creates a new directory. The argument is the name of the new 50 | -- directory.
51 | -- Returns true if the operation was successful; 52 | -- in case of error, it returns nil plus an error string. 53 | function mkdir (dirname) 54 | 55 | --- Removes an existing directory. The argument is the name of the directory.
56 | -- Returns true if the operation was successful; 57 | -- in case of error, it returns nil plus an error string. 58 | function rmdir (dirname) 59 | 60 | --- Set access and modification times of a file. This function is 61 | -- a bind to utime function. The first argument is the 62 | -- filename, the second argument (atime) is the access time, 63 | -- and the third argument (mtime) is the modification time. 64 | -- Both times are provided in seconds (which should be generated with 65 | -- Lua standard function os.date). 66 | -- If the modification time is omitted, the access time provided is used; 67 | -- if both times are omitted, the current time is used.
68 | -- Returns true if the operation was successful; 69 | -- in case of error, it returns nil plus an error string. 70 | function touch (filepath, atime, mtime) 71 | 72 | --- Unlocks a file or a part of it. This function works on 73 | -- open files; the file handle should be specified as the first 74 | -- argument. The optional arguments start and 75 | -- length can be used to specify a starting point and its 76 | -- length; both should be numbers.
77 | -- Returns true if the operation was successful; 78 | -- in case of error, it returns nil plus an error string. 79 | function unlock (filehandle, start, length) 80 | -------------------------------------------------------------------------------- /doc/us/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | LuaDoc: Documentation Generator Tool for the Lua language 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 |
14 | 17 |
LuaDoc
18 |
Documentation Generator Tool for the Lua language
19 |
20 | 21 |
22 | 23 | 64 | 65 |
66 |

Overview

67 | 68 |

69 | LuaDoc is a documentation generator tool for 70 | Lua 71 | source code. 72 | It parses the declarations and documentation comments in a 73 | set of Lua source files and produces a set of XHTML pages describing the 74 | commented declarations and functions. 75 |

76 |

77 | The output is not limited to XHTML. Other formats can be generated by 78 | implementing new doclets. The format of the documentation comments 79 | is also flexible and can be customized by implementing new taglets. 80 | Please refer to customizing section for further 81 | information. 82 |

83 |

84 | LuaDoc is free software and uses the same license as Lua. 85 |

86 | 87 |

Status

88 |

89 | Current version is 3.0.1. 90 | It was developed for Lua 5.1. 91 |

92 | 93 |

Download

94 |

LuaDoc can be downloaded from its 95 | Lua Forge 96 | page. 97 |

98 | 99 |

Dependencies

100 |

LuaDoc depends on two external packages:

101 | 102 | 106 | 107 |

History

108 |
109 |
Version 3.0.1 [17/Feb/2008]
110 |
111 |
    112 |
  • added support to @usage tags (thanks to Rafael Sabbagh Armony)
  • 113 |
  • makefile improved to follow kepler standards
  • 114 |
  • lualogging dependency is now optional
  • 115 |
  • added a rockspec file
  • 116 |
117 |
118 | 119 |
Version 3.0.0 [13/Aug/2007]
120 |
121 |
    122 |
  • update to Lua 5.1
  • 123 |
  • major internal refactoring
  • 124 |
125 |
126 | 127 |
Version 2.0 [14/Aug/2002]
128 |
129 |
    130 |
  • update to Lua 4.0
  • 131 |
132 |
133 | 134 |
Version 1.1 [31/Mar/1999]
135 |
136 |
    137 |
  • "DOS/Windows"-safe sources (no problems with "\r\n" line-breaks)
  • 138 |
  • new usage subsection
  • 139 |
140 |
141 | 142 |
Version 1.0 [15/Mar/1999]
143 |
144 |
145 | 146 |

Credits

147 |

LuaDoc codebase was designed and developed by Tomás Guisasola. 148 | Version 3.0 was refactored by Danilo Tuler and Tomás Guisasola as part 149 | of the 150 | Kepler Project, 151 | which holds its copyright.

152 | 153 |

Contact us

154 | 155 |

156 | For more information please 157 | contact us or join the 158 | Kepler mailing list. 159 | Comments are welcome! 160 |

161 |
162 | 163 |
164 | 165 |
166 |

Valid XHTML 1.0!

167 |

$Id: index.html,v 1.19 2008/02/17 06:42:51 jasonsantos Exp $

168 |
169 | 170 |
171 | 172 | 173 | -------------------------------------------------------------------------------- /doc/us/license.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | LuaDoc: Documentation Generator Tool for the Lua language 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 |
14 | 17 |
LuaDoc
18 |
Documentation Generator Tool for the Lua language
19 |
20 | 21 |
22 | 23 | 64 | 65 |
66 | 67 |

License

68 | 69 |

70 | LuaDoc is free software: it can be used for both academic 71 | and commercial purposes at absolutely no cost. There are no 72 | royalties or GNU-like "copyleft" restrictions. LuaDoc 73 | qualifies as 74 | Open Source 75 | software. 76 | Its licenses are compatible with 77 | GPL. 78 | LuaDoc is not in the public domain and the 79 | Kepler Project 80 | keep its copyright. 81 | The legal details are below. 82 |

83 | 84 |

The spirit of the license is that you are free to use 85 | LuaDoc for any purpose at no cost without having to ask us. 86 | The only requirement is that if you do use LuaDoc, then you 87 | should give us credit by including the appropriate copyright notice 88 | somewhere in your product or its documentation.

89 | 90 |

The LuaDoc is designed and implemented by Danilo Tuler and Tomás Guisasola. 91 | The implementation is not derived from licensed software.

92 | 93 |
94 |

Copyright © 2004-2007 The Kepler Project.

95 | 96 |

Permission is hereby granted, free of charge, to any person 97 | obtaining a copy of this software and associated documentation 98 | files (the "Software"), to deal in the Software without 99 | restriction, including without limitation the rights to use, copy, 100 | modify, merge, publish, distribute, sublicense, and/or sell copies 101 | of the Software, and to permit persons to whom the Software is 102 | furnished to do so, subject to the following conditions:

103 | 104 |

The above copyright notice and this permission notice shall be 105 | included in all copies or substantial portions of the Software.

106 | 107 |

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 108 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 109 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 110 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 111 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 112 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 113 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 114 | SOFTWARE.

115 | 116 |
117 | 118 |
119 | 120 |
121 |

122 | Valid XHTML 1.0!

123 |

$Id: license.html,v 1.6 2007/08/13 15:32:45 carregal Exp $

124 |
125 | 126 |
127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /doc/us/lua.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keplerproject/luadoc/51577bf45502c0fb3ccabdef72fb20a549c63308/doc/us/lua.png -------------------------------------------------------------------------------- /doc/us/manual.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | LuaDoc: Documentation Generator Tool for the Lua language 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 |
14 | 17 |
LuaDoc
18 |
Documentation Generator Tool for the Lua language
19 |
20 | 21 |
22 | 23 | 64 | 65 |
66 | 67 |

Introduction

68 |

LuaDoc is a documentation generation tool for lua source files. It does not 69 | impose a documentation format, but suggests one (XHTML) and implements it. The produced 70 | documentation can be of any type. 71 |

72 | 73 |

74 | LuaDoc can be used out-of-the-box, provided that the source code is documented in 75 | the proposed format. 76 |

77 | 78 |

Installation

79 | 80 |

LuaDoc tool is composed by two parts, a library, and a launcher script.

81 | 82 |

83 | The library follows the 84 | package model 85 | for Lua 5.1 and therefore should be "installed" in your 86 | package.path. 87 |

88 | 89 |

90 | The launcher script, namely luadoc.lua for Unix and luadoc.bat 91 | for Windows, should be installed in your system PATH, so that it can be executed. 92 |

93 | 94 |

95 | LuaDoc also depends on two external packages: 96 | LuaFileSystem and 97 | LuaLogging, and you'll 98 | need to install them accordingly. 99 |

100 | 101 |

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

104 | 105 |
106 | lua5.1 luadoc.lua [options|files]
107 | 
108 | 109 |

110 | This is the main script: it will load LuaDoc library and process the specified 111 | files. Try luadoc.lua --help, it will show you all available options. 112 |

113 | 114 | 115 |

How to comment

116 |

117 | LuaDoc looks for the sequence of three minus signs (---). 118 | This sequence of characters indicates the beginning of a documented comment. 119 | The documentation ends with the first line of code found. 120 |

121 |

122 | The following code defines a function and its documentation. 123 |

124 |
125 | --- Define special sequences of characters.
126 | -- For each pair (find, subs), the function will create a field named with
127 | -- find which has the value of subs.
128 | -- It also creates an index for the table, according to the order of insertion.
129 | -- @param subs The replacement pattern.
130 | -- @param find The pattern to find.
131 | function def_escapes (find, subs)
132 |    local special = { t = "\t", n = "\n", ['"'] = '"', ['\\'] = '\\', }
133 |    find = gsub (find, "\\(.)", function (x) return %special[x] or x end)
134 |    subs = gsub (subs, "\\(.)", function (x) return %special[x] or x end)
135 |    escape_sequences.n = escape_sequences.n+1
136 |    escape_sequences[escape_sequences.n] = find
137 |    escape_sequences[find] = subs
138 | end
139 | 
140 |

141 | The first sentence (until the first period) will be the resume. 142 | The last two, which begins with -- @param, will compound the 143 | parameters section. 144 | The other lines will complete the description of the function. 145 | The corresponding documentation should be something like: 146 |

147 | 148 |
149 |
def_escapes (find, subs)
150 |
151 | Define special sequences of characters. 152 | For each pair (find, subs), the function will create a field named with find which has the value of subs. 153 | It also creates an index for the table, according to the order of insertion. 154 |

Parameters

155 |
    156 |
  • find: The pattern to find.
  • 157 |
  • subs: The replacement pattern.
  • 158 |
159 |
160 |
161 | 162 |

163 | A good example is the LuaDoc system itself. 164 | You can build the documentation by executing the following line from the 165 | LuaDoc directory: 166 |

167 |
168 | luadoc.lua *.lua
169 | 
170 |

171 | It will produce one HTML file for each Lua file and an index file. 172 | You can browse them here. 173 |

174 | 175 | 176 |

Tags

177 |

178 | LuaDoc can parse some tags at each function or table documentation. 179 | Tags are indicated in the source code with a `@' character 180 | followed by the name of the tag: 181 |

182 | 183 |
184 |
@author <text>
185 |
An author of the module or file.
186 | 187 |
@copyright <text>
188 |
The copyright notice of the module or file. 189 | LuaDoc adds a © sign between the label (Copyright) and the 190 | given text (e.g. 2004-2007 Kepler Project).
191 | 192 |
@field
193 |
Describe a table field definition.
194 | 195 |
@param <word> <text>
196 |
Describe function parameters. 197 | It requires the name of the parameter and its description.
198 | 199 |
@release <text>
200 |
Free format string to describe the module or file release.
201 | 202 |
@return <text>
203 |
Describe a returning value of the function. 204 | Since Lua can return multiple values, this tag should appear more 205 | than once.
206 | 207 |
@see <text>
208 |
Refers to other descriptions of functions or tables.
209 | 210 |
@usage <text>
211 |
Describe the usage of the function or variable.
212 |
213 | 214 |

Infered Tags

215 | 216 |

217 | The following tags would be normally infered by LuaDoc, 218 | but they can be used to override the infered value. 219 |

220 | 221 |
222 |
@class <word>
223 |
If LuaDoc cannot infer the type of documentation (function, table or 224 | module definition), the programmer can specify it explicitly.
225 | 226 |
@description
227 |
The description of the function or table. 228 | This is usually infered automatically.
229 | 230 |
@name <word>
231 |
The name of the function or table definition. 232 | This is usually infered from the code analysis, and the programmer does 233 | not need to define it. If LuaDoc can infer the name of the function 234 | automatically it's even not recomended to define the name explicitly, 235 | to avoid redundancy.
236 | 237 |
238 | 239 |

Text indentation and linebreaks

240 |

241 | LuaDoc parses text in such a way that it concatenates text on individual lines 242 | and removes trailing and leading whitespace in the process. To prevent LuaDoc 243 | from doing this and to retain the original linebreaks and indentation end the 244 | tag with a `#' character, for example '@usage#'. 245 | This is especially usefull for multiline code examples in the usage tag, where 246 | you want the example code to remain properly indented for readability. Run 247 | LuaDoc on the included test file to see the results. 248 | Warning; you must make sure that the doclet you are using supports this format. 249 |

250 | 251 | 252 |

Command line options

253 |

254 | The luadoc command line script has some options: 255 |

256 |
257 |
-d <path>
258 |
Defines the output directory path. Default is the current dir.
259 | 260 |
-h, --help
261 |
Show help instructions
262 | 263 |
--noindexpage
264 |
Do not generate the index page.
265 | 266 |
--nofiles
267 |
Do not generate documentation focused on files.
268 | 269 |
--nomodules
270 |
Do not generate documentation focused on modules.
271 | 272 |
--doclet <doclet_module>
273 |
Doclet module used to generate output
274 | 275 |
--taglet <taglet_module>
276 |
Taglet module used to parse input code
277 | 278 |
-q, --quiet
279 |
Suppress info output
280 | 281 |
-v, --version
282 |
Print version information
283 |
284 | 285 |
286 | 287 |
288 | 289 |
290 |

Valid XHTML 1.0!

291 |

$Id: manual.html,v 1.10 2007/10/12 13:33:45 tomas Exp $

292 |
293 | 294 |
295 | 296 | 297 | -------------------------------------------------------------------------------- /rockspecs/luadoc-3.0.1-1.rockspec: -------------------------------------------------------------------------------- 1 | package = "LuaDoc" 2 | version = "3.0.1-1" 3 | source = { 4 | url = "http://luaforge.net/frs/download.php/2557/luadoc-3.0.1.tar.gz" 5 | } 6 | description = { 7 | summary = "LuaDoc is a documentation tool for Lua source code", 8 | detailed = [[ 9 | LuaDoc is a documentation generator tool for Lua source code. 10 | It parses the declarations and documentation comments in a set of 11 | Lua source files and produces a set of XHTML pages describing the 12 | commented declarations and functions. 13 | 14 | The output is not limited to XHTML. Other formats can be generated 15 | by implementing new doclets. The format of the documentation comments 16 | is also flexible and can be customized by implementing new taglets. 17 | ]], 18 | license = "MIT/X11", 19 | homepage = "http://luadoc.luaforge.net/" 20 | } 21 | dependencies = { 22 | "lualogging >= 1.1.3", 23 | "luafilesystem >= 1.2.1", 24 | } 25 | build = { 26 | type = "make", 27 | variables = { 28 | LUA_DIR = "$(LUADIR)", 29 | SYS_BINDIR = "$(BINDIR)" 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /rockspecs/luadoc-cvs-1.rockspec: -------------------------------------------------------------------------------- 1 | package = "LuaDoc" 2 | version = "cvs-1" 3 | source = { 4 | url = "cvs://:pserver:anonymous:@cvs.luaforge.net:/cvsroot/luadoc", 5 | cvs_tag = "HEAD", 6 | } 7 | description = { 8 | summary = "LuaDoc is a documentation tool for Lua source code", 9 | detailed = [[ 10 | LuaDoc is a documentation generator tool for Lua source code. 11 | It parses the declarations and documentation comments in a set of 12 | Lua source files and produces a set of XHTML pages describing the 13 | commented declarations and functions. 14 | 15 | The output is not limited to XHTML. Other formats can be generated 16 | by implementing new doclets. The format of the documentation comments 17 | is also flexible and can be customized by implementing new taglets. 18 | ]], 19 | license = "MIT/X11", 20 | homepage = "http://luadoc.luaforge.net/" 21 | } 22 | dependencies = { 23 | "lualogging >= 1.1.3", 24 | "luafilesystem >= 1.2.1", 25 | } 26 | build = { 27 | type = "make", 28 | variables = { 29 | LUA_DIR = "$(LUADIR)", 30 | SYS_BINDIR = "$(BINDIR)" 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/luadoc.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | lua5.1 c:\lua5.1\luadoc_start.lua %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /src/luadoc.lua.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | ------------------------------------------------------------------------------- 3 | -- LuaDoc launcher. 4 | -- @release $Id: luadoc.lua.in,v 1.1 2008/02/17 06:42:51 jasonsantos Exp $ 5 | ------------------------------------------------------------------------------- 6 | 7 | require "luadoc" 8 | 9 | ------------------------------------------------------------------------------- 10 | -- Print version number. 11 | 12 | local function print_version () 13 | print (string.format("%s\n%s\n%s", 14 | luadoc._VERSION, 15 | luadoc._DESCRIPTION, 16 | luadoc._COPYRIGHT)) 17 | end 18 | 19 | ------------------------------------------------------------------------------- 20 | -- Print usage message. 21 | 22 | local function print_help () 23 | print ("Usage: "..arg[0]..[[ [options|files] 24 | Generate documentation from files. Available options are: 25 | -d path output directory path 26 | -t path template directory path 27 | -h, --help print this help and exit 28 | --noindexpage do not generate global index page 29 | --nofiles do not generate documentation for files 30 | --nomodules do not generate documentation for modules 31 | --doclet doclet_module doclet module to generate output 32 | --taglet taglet_module taglet module to parse input code 33 | -q, --quiet suppress all normal output 34 | -v, --version print version information]]) 35 | end 36 | 37 | local function off_messages (arg, i, options) 38 | options.verbose = nil 39 | end 40 | 41 | ------------------------------------------------------------------------------- 42 | -- Process options. TODO: use getopts. 43 | -- @class table 44 | -- @name OPTIONS 45 | 46 | local OPTIONS = { 47 | d = function (arg, i, options) 48 | local dir = arg[i+1] 49 | if string.sub (dir, -2) ~= "/" then 50 | dir = dir..'/' 51 | end 52 | options.output_dir = dir 53 | return 1 54 | end, 55 | t = function (arg, i, options) 56 | local dir = arg[i+1] 57 | if string.sub (dir, -2) ~= "/" then 58 | dir = dir..'/' 59 | end 60 | options.template_dir = dir 61 | return 1 62 | end, 63 | h = print_help, 64 | help = print_help, 65 | q = off_messages, 66 | quiet = off_messages, 67 | v = print_version, 68 | version = print_version, 69 | doclet = function (arg, i, options) 70 | options.doclet = arg[i+1] 71 | return 1 72 | end, 73 | taglet = function (arg, i, options) 74 | options.taglet = arg[i+1] 75 | return 1 76 | end, 77 | } 78 | 79 | ------------------------------------------------------------------------------- 80 | 81 | local function process_options (arg) 82 | local files = {} 83 | local options = require "luadoc.config" 84 | local i = 1 85 | while i <= #arg do 86 | local argi = arg[i] 87 | if string.sub (argi, 1, 1) ~= '-' then 88 | table.insert (files, argi) 89 | else 90 | local opt = string.sub (argi, 2) 91 | if string.sub (opt, 1, 1) == '-' then 92 | opt = string.gsub (opt, "%-", "") 93 | end 94 | if OPTIONS[opt] then 95 | if OPTIONS[opt] (arg, i, options) then 96 | i = i + 1 97 | end 98 | else 99 | options[opt] = 1 100 | end 101 | end 102 | i = i+1 103 | end 104 | return files, options 105 | end 106 | 107 | ------------------------------------------------------------------------------- 108 | -- Main function. Process command-line parameters and call luadoc processor. 109 | 110 | function main (arg) 111 | -- Process options 112 | local argc = #arg 113 | if argc < 1 then 114 | print_help () 115 | return 116 | end 117 | local files, options = process_options (arg) 118 | return luadoc.main(files, options) 119 | end 120 | 121 | main(arg) 122 | -------------------------------------------------------------------------------- /src/luadoc/config.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- LuaDoc configuration file. This file contains the default options for 3 | -- luadoc operation. These options can be overriden by the command line tool 4 | -- @see luadoc.print_help 5 | -- @release $Id: config.lua,v 1.6 2007/04/18 14:28:39 tomas Exp $ 6 | ------------------------------------------------------------------------------- 7 | 8 | module "luadoc.config" 9 | 10 | ------------------------------------------------------------------------------- 11 | -- Default options 12 | -- @class table 13 | -- @name default_options 14 | -- @field output_dir default output directory for generated documentation, used 15 | -- by several doclets 16 | -- @field taglet parser used to analyze source code input 17 | -- @field doclet documentation generator 18 | -- @field template_dir directory with documentation templates, used by the html 19 | -- doclet 20 | -- @field verbose command line tool configuration to output processing 21 | -- information 22 | 23 | local default_options = { 24 | output_dir = "", 25 | taglet = "luadoc.taglet.standard", 26 | doclet = "luadoc.doclet.html", 27 | -- TODO: find a way to define doclet specific options 28 | template_dir = "luadoc/doclet/html/", 29 | nomodules = false, 30 | nofiles = false, 31 | verbose = true, 32 | } 33 | 34 | return default_options 35 | -------------------------------------------------------------------------------- /src/luadoc/doclet/debug.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------- 2 | -- LuaDoc debugging facilities. 3 | -- @release $Id: debug.lua,v 1.3 2007/04/18 14:28:39 tomas Exp $ 4 | ----------------------------------------------------------------- 5 | 6 | module "luadoc.doclet.debug" 7 | 8 | function printline() 9 | print(string.rep('-', 79)) 10 | end 11 | 12 | ----------------------------------------------------------------- 13 | -- Print debug information about document 14 | -- @param doc Table with the structured documentation. 15 | 16 | function start (doc) 17 | print("Files:") 18 | for _, filepath in ipairs(doc.files) do 19 | print('\t', filepath) 20 | end 21 | printline() 22 | 23 | print("Modules:") 24 | for _, modulename in ipairs(doc.modules) do 25 | print('\t', modulename) 26 | end 27 | printline() 28 | 29 | for i, v in pairs(doc.files) do 30 | print('\t', i, v) 31 | end 32 | printline() 33 | for i, v in pairs(doc.files[doc.files[1]]) do 34 | print(i, v) 35 | end 36 | 37 | printline() 38 | for i, v in pairs(doc.files[doc.files[1]].doc[1]) do 39 | print(i, v) 40 | end 41 | printline() 42 | print("Params") 43 | for i, v in pairs(doc.files[doc.files[1]].doc[1].param) do 44 | print(i, v) 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /src/luadoc/doclet/formatter.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Doclet to format source code according to LuaDoc standard tags. This doclet 3 | -- (re)write .lua files adding missing standard tags. Texts are formatted to 4 | -- 80 columns and function parameters are added based on code analysis. 5 | -- 6 | -- @release $Id: formatter.lua,v 1.5 2007/04/18 14:28:39 tomas Exp $ 7 | ------------------------------------------------------------------------------- 8 | 9 | local util = require "luadoc.util" 10 | local assert, ipairs, pairs, type = assert, ipairs, pairs, type 11 | local string = require"string" 12 | local table = require"table" 13 | 14 | module "luadoc.doclet.formatter" 15 | 16 | options = { 17 | output_dir = "./", 18 | } 19 | 20 | ------------------------------------------------------------------------------- 21 | -- Assembly the output filename for an input file. 22 | -- TODO: change the name of this function 23 | function out_file (filename) 24 | local h = filename 25 | h = options.output_dir..h 26 | return h 27 | end 28 | 29 | ------------------------------------------------------------------------------- 30 | -- Generate a new lua file for each input lua file. If the user does not 31 | -- specify a different output directory input files will be rewritten. 32 | -- @param doc documentation table 33 | 34 | function start (doc) 35 | local todo = "" 36 | 37 | -- Process files 38 | for i, file_doc in ipairs(doc.files) do 39 | -- assembly the filename 40 | local filename = out_file(file_doc.name) 41 | luadoc.logger:info(string.format("generating file `%s'", filename)) 42 | 43 | -- TODO: confirm file overwrite 44 | local f = lfs.open(filename, "w") 45 | assert(f, string.format("could not open `%s' for writing", filename)) 46 | 47 | for _, block in ipairs(file_doc.doc) do 48 | 49 | -- write reorganized comments 50 | f:write(string.rep("-", 80).."\n") 51 | 52 | -- description 53 | f:write(util.comment(util.wrap(block.description, 77))) 54 | f:write("\n") 55 | 56 | if block.class == "function" then 57 | -- parameters 58 | table.foreachi(block.param, function (_, param_name) 59 | f:write(util.comment(util.wrap(string.format("@param %s %s", param_name, block.param[param_name] or todo), 77))) 60 | f:write("\n") 61 | end) 62 | 63 | -- return 64 | if type(block.ret) == "table" then 65 | table.foreachi(block.ret, function (_, ret) 66 | f:write(util.comment(util.wrap(string.format("@return %s", ret), 77)).."\n") 67 | end) 68 | else 69 | f:write(util.comment(util.wrap(string.format("@return %s", block.ret or todo), 77)).."\n") 70 | end 71 | end 72 | 73 | -- TODO: usage 74 | -- TODO: see 75 | 76 | -- write code 77 | for _, line in ipairs(block.code) do 78 | f:write(line.."\n") 79 | end 80 | end 81 | 82 | f:close() 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /src/luadoc/doclet/html.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Doclet that generates HTML output. This doclet generates a set of html files 3 | -- based on a group of templates. The main templates are: 4 | -- 11 | -- 12 | -- @release $Id: html.lua,v 1.29 2007/12/21 17:50:48 tomas Exp $ 13 | ------------------------------------------------------------------------------- 14 | 15 | local assert, getfenv, ipairs, loadstring, pairs, setfenv, tostring, tonumber, type = assert, getfenv, ipairs, loadstring, pairs, setfenv, tostring, tonumber, type 16 | local io = require"io" 17 | local lfs = require "lfs" 18 | local lp = require "luadoc.lp" 19 | local luadoc = require"luadoc" 20 | local package = package 21 | local string = require"string" 22 | local table = require"table" 23 | 24 | module "luadoc.doclet.html" 25 | 26 | ------------------------------------------------------------------------------- 27 | -- Looks for a file `name' in given path. Removed from compat-5.1 28 | -- @param path String with the path. 29 | -- @param name String with the name to look for. 30 | -- @return String with the complete path of the file found 31 | -- or nil in case the file is not found. 32 | 33 | local function search (path, name) 34 | for c in string.gfind(path, "[^;]+") do 35 | c = string.gsub(c, "%?", name) 36 | local f = io.open(c) 37 | if f then -- file exist? 38 | f:close() 39 | return c 40 | end 41 | end 42 | return nil -- file not found 43 | end 44 | 45 | ------------------------------------------------------------------------------- 46 | -- Include the result of a lp template into the current stream. 47 | 48 | function include (template, env) 49 | -- template_dir is relative to package.path 50 | local templatepath = options.template_dir .. template 51 | 52 | -- search using package.path (modified to search .lp instead of .lua 53 | local search_path = string.gsub(package.path, "%.lua", "") 54 | local templatepath = search(search_path, templatepath) 55 | assert(templatepath, string.format("template `%s' not found", template)) 56 | 57 | env = env or {} 58 | env.table = table 59 | env.io = io 60 | env.lp = lp 61 | env.ipairs = ipairs 62 | env.tonumber = tonumber 63 | env.tostring = tostring 64 | env.type = type 65 | env.luadoc = luadoc 66 | env.options = options 67 | 68 | return lp.include(templatepath, env) 69 | end 70 | 71 | ------------------------------------------------------------------------------- 72 | -- Returns a link to a html file, appending "../" to the link to make it right. 73 | -- @param html Name of the html file to link to 74 | -- @return link to the html file 75 | 76 | function link (html, from) 77 | local h = html 78 | from = from or "" 79 | string.gsub(from, "/", function () h = "../" .. h end) 80 | return h 81 | end 82 | 83 | ------------------------------------------------------------------------------- 84 | -- Returns the name of the html file to be generated from a module. 85 | -- Files with "lua" or "luadoc" extensions are replaced by "html" extension. 86 | -- @param modulename Name of the module to be processed, may be a .lua file or 87 | -- a .luadoc file. 88 | -- @return name of the generated html file for the module 89 | 90 | function module_link (modulename, doc, from) 91 | -- TODO: replace "." by "/" to create directories? 92 | -- TODO: how to deal with module names with "/"? 93 | assert(modulename) 94 | assert(doc) 95 | from = from or "" 96 | 97 | if doc.modules[modulename] == nil then 98 | -- logger:error(string.format("unresolved reference to module `%s'", modulename)) 99 | return 100 | end 101 | 102 | local href = "modules/" .. modulename .. ".html" 103 | string.gsub(from, "/", function () href = "../" .. href end) 104 | return href 105 | end 106 | 107 | ------------------------------------------------------------------------------- 108 | -- Returns the name of the html file to be generated from a lua(doc) file. 109 | -- Files with "lua" or "luadoc" extensions are replaced by "html" extension. 110 | -- @param to Name of the file to be processed, may be a .lua file or 111 | -- a .luadoc file. 112 | -- @param from path of where am I, based on this we append ..'s to the 113 | -- beginning of path 114 | -- @return name of the generated html file 115 | 116 | function file_link (to, from) 117 | assert(to) 118 | from = from or "" 119 | 120 | local href = to 121 | href = string.gsub(href, "lua$", "html") 122 | href = string.gsub(href, "luadoc$", "html") 123 | href = "files/" .. href 124 | string.gsub(from, "/", function () href = "../" .. href end) 125 | return href 126 | end 127 | 128 | ------------------------------------------------------------------------------- 129 | -- Returns a link to a function or to a table 130 | -- @param fname name of the function or table to link to. 131 | -- @param doc documentation table 132 | -- @param kind String specying the kinf of element to link ("functions" or "tables"). 133 | 134 | function link_to (fname, doc, module_doc, file_doc, from, kind) 135 | assert(fname) 136 | assert(doc) 137 | from = from or "" 138 | kind = kind or "functions" 139 | 140 | if file_doc then 141 | for _, func_name in pairs(file_doc[kind]) do 142 | if func_name == fname then 143 | return file_link(file_doc.name, from) .. "#" .. fname 144 | end 145 | end 146 | end 147 | 148 | local _, _, modulename, fname = string.find(fname, "^(.-)[%.%:]?([^%.%:]*)$") 149 | assert(fname) 150 | 151 | -- if fname does not specify a module, use the module_doc 152 | if string.len(modulename) == 0 and module_doc then 153 | modulename = module_doc.name 154 | end 155 | 156 | local module_doc = doc.modules[modulename] 157 | if not module_doc then 158 | -- logger:error(string.format("unresolved reference to function `%s': module `%s' not found", fname, modulename)) 159 | return 160 | end 161 | 162 | for _, func_name in pairs(module_doc[kind]) do 163 | if func_name == fname then 164 | return module_link(modulename, doc, from) .. "#" .. fname 165 | end 166 | end 167 | 168 | -- logger:error(string.format("unresolved reference to function `%s' of module `%s'", fname, modulename)) 169 | end 170 | 171 | ------------------------------------------------------------------------------- 172 | -- Make a link to a file, module or function 173 | 174 | function symbol_link (symbol, doc, module_doc, file_doc, from) 175 | assert(symbol) 176 | assert(doc) 177 | 178 | local href = 179 | -- file_link(symbol, from) or 180 | module_link(symbol, doc, from) or 181 | link_to(symbol, doc, module_doc, file_doc, from, "functions") or 182 | link_to(symbol, doc, module_doc, file_doc, from, "tables") 183 | 184 | if not href then 185 | logger:error(string.format("unresolved reference to symbol `%s'", symbol)) 186 | end 187 | 188 | return href or "" 189 | end 190 | 191 | ------------------------------------------------------------------------------- 192 | -- Assembly the output filename for an input file. 193 | -- TODO: change the name of this function 194 | function out_file (filename) 195 | local h = filename 196 | h = string.gsub(h, "lua$", "html") 197 | h = string.gsub(h, "luadoc$", "html") 198 | h = "files/" .. h 199 | -- h = options.output_dir .. string.gsub (h, "^.-([%w_]+%.html)$", "%1") 200 | h = options.output_dir .. h 201 | return h 202 | end 203 | 204 | ------------------------------------------------------------------------------- 205 | -- Assembly the output filename for a module. 206 | -- TODO: change the name of this function 207 | function out_module (modulename) 208 | local h = modulename .. ".html" 209 | h = "modules/" .. h 210 | h = options.output_dir .. h 211 | return h 212 | end 213 | 214 | ------------------------------------------------------------------------------- 215 | -- Update a table to make all string values refelect html tags for linebreaks 216 | -- a leading spaces. 217 | function fixhtmltable (doc) 218 | for k,v in pairs(doc) do 219 | if type(v) == "string" then 220 | -- update string value 221 | local s = string.gsub(v, "\n", "
") 222 | s = string.gsub(s, "
", "
 ") 223 | while string.find(s, "  ") do 224 | s = string.gsub(s, "  ", "  ") 225 | end 226 | doc[k] = s 227 | elseif type(v) == "table" then 228 | -- recurse update table 229 | fixhtmltable(v) 230 | end 231 | end 232 | end 233 | 234 | ----------------------------------------------------------------- 235 | -- Generate the output. 236 | -- @param doc Table with the structured documentation. 237 | 238 | function start (doc) 239 | -- Pre proces doc table, replacing linebreaks and leading space by html equiv. 240 | fixhtmltable(doc) 241 | -- Generate index file 242 | if (#doc.files > 0 or #doc.modules > 0) and (not options.noindexpage) then 243 | local filename = options.output_dir.."index.html" 244 | logger:info(string.format("generating file `%s'", filename)) 245 | local f = lfs.open(filename, "w") 246 | assert(f, string.format("could not open `%s' for writing", filename)) 247 | io.output(f) 248 | include("index.lp", { doc = doc }) 249 | f:close() 250 | end 251 | 252 | -- Process modules 253 | if not options.nomodules then 254 | for _, modulename in ipairs(doc.modules) do 255 | local module_doc = doc.modules[modulename] 256 | -- assembly the filename 257 | local filename = out_module(modulename) 258 | logger:info(string.format("generating file `%s'", filename)) 259 | 260 | local f = lfs.open(filename, "w") 261 | assert(f, string.format("could not open `%s' for writing", filename)) 262 | io.output(f) 263 | include("module.lp", { doc = doc, module_doc = module_doc }) 264 | f:close() 265 | end 266 | end 267 | 268 | -- Process files 269 | if not options.nofiles then 270 | for _, filepath in ipairs(doc.files) do 271 | local file_doc = doc.files[filepath] 272 | -- assembly the filename 273 | local filename = out_file(file_doc.name) 274 | logger:info(string.format("generating file `%s'", filename)) 275 | 276 | local f = lfs.open(filename, "w") 277 | assert(f, string.format("could not open `%s' for writing", filename)) 278 | io.output(f) 279 | include("file.lp", { doc = doc, file_doc = file_doc} ) 280 | f:close() 281 | end 282 | end 283 | 284 | -- copy extra files 285 | local f = lfs.open(options.output_dir.."luadoc.css", "w") 286 | io.output(f) 287 | include("luadoc.css") 288 | f:close() 289 | end 290 | -------------------------------------------------------------------------------- /src/luadoc/doclet/html/file.lp: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Luadocs for <%= file_doc.name %> 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 |
15 | 16 |
17 |
18 |
19 | 20 |
21 | 22 | 26 | 27 |
28 | 29 |

File <%=file_doc.name%>

30 | 31 | <%if file_doc.description then%> 32 |

<%=file_doc.description%>

33 | <%end%> 34 | <%if file_doc.author then%> 35 |

<%= #file_doc.author>1 and "Authors" or "Author" %>: 36 | 37 | <%for _, author in ipairs(file_doc.author) do%> 38 | 39 | <%end%> 40 |
<%= author %>
41 |

42 | <%end%> 43 | <%if file_doc.copyright then%> 44 |

Copyright ©<%=file_doc.copyright%>

45 | <%end%> 46 | <%if file_doc.release then%> 47 |

Release: <%=file_doc.release%>

48 | <%end%> 49 | 50 | <%if #file_doc.functions > 0 then%> 51 |

Functions

52 | 53 | <%for _, func_name in ipairs(file_doc.functions) do 54 | local func_data = file_doc.functions[func_name]%> 55 | 56 | 57 | 58 | 59 | <%end%> 60 |
<%=func_data.private and "local " or ""%><%=func_name%> (<%=table.concat(func_data.param, ", ")%>)<%=func_data.summary%>
61 | <%end%> 62 | 63 | 64 | <%if #file_doc.tables > 0 then%> 65 |

Tables

66 | 67 | <%for _, tab_name in ipairs(file_doc.tables) do%> 68 | 69 | 70 | 71 | 72 | <%end%> 73 |
<%=tab_name%><%=file_doc.tables[tab_name].summary%>
74 | <%end%> 75 | 76 | 77 |
78 |
79 | 80 | 81 | 82 | <%if #file_doc.functions > 0 then%> 83 |

Functions

84 |
85 | <%for _, func_name in ipairs(file_doc.functions) do%> 86 | <%=luadoc.doclet.html.include("function.lp", { doc=doc, file_doc=file_doc, func=file_doc.functions[func_name] })%> 87 | <%end%> 88 |
89 | <%end%> 90 | 91 | 92 | <%if #file_doc.tables > 0 then%> 93 |

Tables

94 |
95 | <%for _, tab_name in ipairs(file_doc.tables) do%> 96 | <%=luadoc.doclet.html.include("table.lp", { doc=doc, file_doc=file_doc, tab=file_doc.tables[tab_name] })%> 97 | <%end%> 98 |
99 | <%end%> 100 | 101 | 102 | 103 |
104 | 105 |
106 | 107 |
108 |

Valid XHTML 1.0!

109 |
110 | 111 |
112 | 113 | 114 | -------------------------------------------------------------------------------- /src/luadoc/doclet/html/function.lp: -------------------------------------------------------------------------------- 1 | <% 2 | if module_doc then 3 | from = "modules/"..module_doc.name 4 | elseif file_doc then 5 | from = "files/.."..file_doc.name 6 | else 7 | from = "" 8 | end 9 | %> 10 | 11 |
<%=func.private and "local " or ""%><%=func.name%> (<%=table.concat(func.param, ", ")%>)
12 |
13 | <%=func.description or ""%> 14 | 15 | <%if type(func.param) == "table" and #func.param > 0 then%> 16 |

Parameters

17 | 24 | <%end%> 25 | 26 | 27 | <%if type(func.usage) == "string" then%> 28 |

Usage:

29 | <%=func.usage%> 30 | <%elseif type(func.usage) == "table" then%> 31 |

Usage

32 | 37 | <%end%> 38 | 39 | <%if type(func.ret) == "string" then%> 40 |

Return value:

41 | <%=func.ret%> 42 | <%elseif type(func.ret) == "table" then%> 43 |

Return values:

44 |
    45 | <%for _, ret in ipairs(func.ret) do%> 46 |
  1. <%= ret %> 47 | <%end%> 48 |
49 | <%end%> 50 | 51 | <%if type(func.see) == "string" then %> 52 |

See also:

53 | <%=func.see%> 54 | <%elseif type(func.see) == "table" and #func.see > 0 then %> 55 |

See also:

56 | 63 | <%end%> 64 |
65 | -------------------------------------------------------------------------------- /src/luadoc/doclet/html/index.lp: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | <% if not options.nomodules and doc.modules[1] then %> 7 | <%= ("%s: "):format(doc.modules[1]) %> 8 | <% end %> Luadocs Index 9 | " type="text/css" /> 10 | 11 | 12 | 13 | 14 |
15 | 16 |
17 | 18 |
19 |
20 |
21 | 22 |
23 | 24 | 28 | 29 |
30 | 31 | 32 | <%if not options.nomodules and #doc.modules > 0 then%> 33 |

Modules

34 | 35 | 36 | <%for _, modulename in ipairs(doc.modules) do%> 37 | 38 | 39 | 40 | 41 | <%end%> 42 |
<%=modulename%><%=doc.modules[modulename].summary%>
43 | <%end%> 44 | 45 | 46 | 47 | <%if not options.nofiles and #doc.files > 0 then%> 48 |

Files

49 | 50 | 51 | <%for _, filepath in ipairs(doc.files) do%> 52 | 53 | 54 | 55 | 56 | <%end%> 57 |
<%=filepath%>
58 | <%end%> 59 | 60 |
61 | 62 |
63 | 64 |
65 |

Valid XHTML 1.0!

66 |
67 | 68 |
69 | 70 | 71 | -------------------------------------------------------------------------------- /src/luadoc/doclet/html/luadoc.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin-left: 1em; 3 | margin-right: 1em; 4 | font-family: arial, helvetica, geneva, sans-serif; 5 | background-color:#ffffff; margin:0px; 6 | } 7 | 8 | code { 9 | font-family: "Andale Mono", monospace; 10 | } 11 | 12 | tt { 13 | font-family: "Andale Mono", monospace; 14 | } 15 | 16 | body, td, th { font-size: 11pt; } 17 | 18 | h1, h2, h3, h4 { margin-left: 0em; } 19 | 20 | textarea, pre, tt { font-size:10pt; } 21 | body, td, th { color:#000000; } 22 | small { font-size:0.85em; } 23 | h1 { font-size:1.5em; } 24 | h2 { font-size:1.25em; } 25 | h3 { font-size:1.15em; } 26 | h4 { font-size:1.06em; } 27 | 28 | a:link { font-weight:bold; color: #004080; text-decoration: none; } 29 | a:visited { font-weight:bold; color: #006699; text-decoration: none; } 30 | a:link:hover { text-decoration:underline; } 31 | hr { color:#cccccc } 32 | img { border-width: 0px; } 33 | 34 | 35 | h3 { padding-top: 1em; } 36 | 37 | p { margin-left: 1em; } 38 | 39 | p.name { 40 | font-family: "Andale Mono", monospace; 41 | padding-top: 1em; 42 | margin-left: 0em; 43 | } 44 | 45 | blockquote { margin-left: 3em; } 46 | 47 | pre.example { 48 | background-color: rgb(245, 245, 245); 49 | border-top-width: 1px; 50 | border-right-width: 1px; 51 | border-bottom-width: 1px; 52 | border-left-width: 1px; 53 | border-top-style: solid; 54 | border-right-style: solid; 55 | border-bottom-style: solid; 56 | border-left-style: solid; 57 | border-top-color: silver; 58 | border-right-color: silver; 59 | border-bottom-color: silver; 60 | border-left-color: silver; 61 | padding: 1em; 62 | margin-left: 1em; 63 | margin-right: 1em; 64 | font-family: "Andale Mono", monospace; 65 | font-size: smaller; 66 | } 67 | 68 | 69 | hr { 70 | margin-left: 0em; 71 | background: #00007f; 72 | border: 0px; 73 | height: 1px; 74 | } 75 | 76 | ul { list-style-type: disc; } 77 | 78 | table.index { border: 1px #00007f; } 79 | table.index td { text-align: left; vertical-align: top; } 80 | table.index ul { padding-top: 0em; margin-top: 0em; } 81 | 82 | table { 83 | border: 1px solid black; 84 | border-collapse: collapse; 85 | margin-left: auto; 86 | margin-right: auto; 87 | } 88 | th { 89 | border: 1px solid black; 90 | padding: 0.5em; 91 | } 92 | td { 93 | border: 1px solid black; 94 | padding: 0.5em; 95 | } 96 | div.header, div.footer { margin-left: 0em; } 97 | 98 | #container 99 | { 100 | margin-left: 1em; 101 | margin-right: 1em; 102 | background-color: #f0f0f0; 103 | } 104 | 105 | #product 106 | { 107 | text-align: center; 108 | border-bottom: 1px solid #cccccc; 109 | background-color: #ffffff; 110 | } 111 | 112 | #product big { 113 | font-size: 2em; 114 | } 115 | 116 | #product_logo 117 | { 118 | } 119 | 120 | #product_name 121 | { 122 | } 123 | 124 | #product_description 125 | { 126 | } 127 | 128 | #main 129 | { 130 | background-color: #f0f0f0; 131 | border-left: 2px solid #cccccc; 132 | } 133 | 134 | #navigation 135 | { 136 | float: left; 137 | width: 18em; 138 | margin: 0; 139 | vertical-align: top; 140 | background-color: #f0f0f0; 141 | overflow:visible; 142 | } 143 | 144 | #navigation h1 { 145 | background-color:#e7e7e7; 146 | font-size:1.1em; 147 | color:#000000; 148 | text-align:left; 149 | margin:0px; 150 | padding:0.2em; 151 | border-top:1px solid #dddddd; 152 | border-bottom:1px solid #dddddd; 153 | } 154 | 155 | #navigation ul 156 | { 157 | font-size:1em; 158 | list-style-type: none; 159 | padding: 0; 160 | margin: 1px; 161 | } 162 | 163 | #navigation li 164 | { 165 | text-indent: -1em; 166 | margin: 0em 0em 0em 0.5em; 167 | display: block; 168 | padding: 3px 0px 0px 12px; 169 | } 170 | 171 | #navigation li li a 172 | { 173 | padding: 0px 3px 0px -1em; 174 | } 175 | 176 | #content 177 | { 178 | margin-left: 18em; 179 | padding: 1em; 180 | border-left: 2px solid #cccccc; 181 | border-right: 2px solid #cccccc; 182 | background-color: #ffffff; 183 | } 184 | 185 | #about 186 | { 187 | clear: both; 188 | margin: 0; 189 | padding: 5px; 190 | border-top: 2px solid #cccccc; 191 | background-color: #ffffff; 192 | } 193 | 194 | @media print { 195 | body { 196 | font: 12pt "Times New Roman", "TimeNR", Times, serif; 197 | } 198 | a { font-weight:bold; color: #004080; text-decoration: underline; } 199 | 200 | #main { background-color: #ffffff; border-left: 0px; } 201 | #container { margin-left: 2%; margin-right: 2%; background-color: #ffffff; } 202 | 203 | #content { margin-left: 0px; padding: 1em; border-left: 0px; border-right: 0px; background-color: #ffffff; } 204 | 205 | #navigation { display: none; 206 | } 207 | pre.example { 208 | font-family: "Andale Mono", monospace; 209 | font-size: 10pt; 210 | page-break-inside: avoid; 211 | } 212 | } 213 | 214 | table.module_list td 215 | { 216 | border-width: 1px; 217 | padding: 3px; 218 | border-style: solid; 219 | border-color: #cccccc; 220 | } 221 | table.module_list td.name { background-color: #f0f0f0; } 222 | table.module_list td.summary { width: 100%; } 223 | 224 | table.file_list 225 | { 226 | border-width: 1px; 227 | border-style: solid; 228 | border-color: #cccccc; 229 | border-collapse: collapse; 230 | } 231 | table.file_list td 232 | { 233 | border-width: 1px; 234 | padding: 3px; 235 | border-style: solid; 236 | border-color: #cccccc; 237 | } 238 | table.file_list td.name { background-color: #f0f0f0; } 239 | table.file_list td.summary { width: 100%; } 240 | 241 | 242 | table.function_list 243 | { 244 | border-width: 1px; 245 | border-style: solid; 246 | border-color: #cccccc; 247 | border-collapse: collapse; 248 | } 249 | table.function_list td 250 | { 251 | border-width: 1px; 252 | padding: 3px; 253 | border-style: solid; 254 | border-color: #cccccc; 255 | } 256 | table.function_list td.name { background-color: #f0f0f0; } 257 | table.function_list td.summary { width: 100%; } 258 | 259 | 260 | table.table_list 261 | { 262 | border-width: 1px; 263 | border-style: solid; 264 | border-color: #cccccc; 265 | border-collapse: collapse; 266 | } 267 | table.table_list td 268 | { 269 | border-width: 1px; 270 | padding: 3px; 271 | border-style: solid; 272 | border-color: #cccccc; 273 | } 274 | table.table_list td.name { background-color: #f0f0f0; } 275 | table.table_list td.summary { width: 100%; } 276 | 277 | dl.function dt {border-top: 1px solid #ccc; padding-top: 1em;} 278 | dl.function dd {padding-bottom: 1em;} 279 | dl.function h3 {padding: 0; margin: 0; font-size: medium;} 280 | 281 | dl.table dt {border-top: 1px solid #ccc; padding-top: 1em;} 282 | dl.table dd {padding-bottom: 1em;} 283 | dl.table h3 {padding: 0; margin: 0; font-size: medium;} 284 | 285 | #TODO: make module_list, file_list, function_list, table_list inherit from a list 286 | 287 | -------------------------------------------------------------------------------- /src/luadoc/doclet/html/menu.lp: -------------------------------------------------------------------------------- 1 | <% 2 | if module_doc then 3 | from = "modules/"..module_doc.name 4 | elseif file_doc then 5 | from = "files/.."..file_doc.name 6 | else 7 | from = "" 8 | end 9 | %> 10 | 11 |

LuaDoc

12 | 19 | 20 | 21 | 22 | <%if not options.nomodules and #doc.modules > 0 then%> 23 |

Modules

24 | 35 | <%end%> 36 | 37 | 38 | 39 | <%if not options.nofiles and #doc.files > 0 then%> 40 |

Files

41 | 52 | <%end%> 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/luadoc/doclet/html/module.lp: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | <%= module_doc.name %>: Module Index 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 |
15 | 16 |
17 |
18 |
19 | 20 |
21 | 22 | 26 | 27 |
28 | 29 |

Module <%=module_doc.name%>

30 | 31 |

<%=module_doc.description%>

32 | <%if module_doc.author then%> 33 |

<%= #module_doc.author>1 and "Authors" or "Author" %>: 34 | 35 | <%for _, author in ipairs(module_doc.author) do%> 36 | 37 | <%end%> 38 |
<%= author %>
39 |

40 | <%end%> 41 | <%if module_doc.copyright then%> 42 |

Copyright© <%=module_doc.copyright%>

43 | <%end%> 44 | <%if module_doc.release then%> 45 |

Release: <%=module_doc.release%>

46 | <%end%> 47 | 48 | <%if #module_doc.functions > 0 then%> 49 |

Functions

50 | 51 | <%for _, func_name in ipairs(module_doc.functions) do 52 | local func_data = module_doc.functions[func_name]%> 53 | 54 | 55 | 56 | 57 | <%end%> 58 |
<%=func_data.private and "local " or ""%><%=func_name%> (<%=table.concat(module_doc.functions[func_name].param, ", ")%>)<%=module_doc.functions[func_name].summary%>
59 | <%end%> 60 | 61 | 62 | <%if #module_doc.tables > 0 then%> 63 |

Tables

64 | 65 | <%for _, tab_name in ipairs(module_doc.tables) do%> 66 | 67 | 68 | 69 | 70 | <%end%> 71 |
<%=tab_name%><%=module_doc.tables[tab_name].summary%>
72 | <%end%> 73 | 74 | 75 |
76 |
77 | 78 | 79 | <%if #module_doc.functions > 0 then%> 80 |

Functions

81 |
82 | <%for _, func_name in ipairs(module_doc.functions) do%> 83 | <%=luadoc.doclet.html.include("function.lp", { doc=doc, module_doc=module_doc, func=module_doc.functions[func_name] })%> 84 | <%end%> 85 |
86 | <%end%> 87 | 88 | 89 | <%if #module_doc.tables > 0 then%> 90 |

Tables

91 |
92 | <%for _, tab_name in ipairs(module_doc.tables) do%> 93 | <%=luadoc.doclet.html.include("table.lp", { doc=doc, module_doc=module_doc, tab=module_doc.tables[tab_name] })%> 94 | <%end%> 95 |
96 | <%end%> 97 | 98 | 99 |
100 | 101 |
102 | 103 |
104 |

Valid XHTML 1.0!

105 |
106 | 107 |
108 | 109 | 110 | -------------------------------------------------------------------------------- /src/luadoc/doclet/html/table.lp: -------------------------------------------------------------------------------- 1 |
<%=tab.name%>
2 |
<%=tab.description%> 3 | 4 | <%if type(tab.field) == "table" and #tab.field > 0 then%> 5 |

Fields

6 | 13 | <%end%> 14 | 15 |
16 | -------------------------------------------------------------------------------- /src/luadoc/doclet/raw.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------- 2 | -- @release $Id: raw.lua,v 1.5 2007/04/18 14:28:39 tomas Exp $ 3 | ----------------------------------------------------------------- 4 | 5 | module "luadoc.doclet.raw" 6 | 7 | ----------------------------------------------------------------- 8 | -- Generate the output. 9 | -- @param doc Table with the structured documentation. 10 | 11 | function start (doc) 12 | end 13 | -------------------------------------------------------------------------------- /src/luadoc/init.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- LuaDoc main function. 3 | -- @release $Id: init.lua,v 1.4 2008/02/17 06:42:51 jasonsantos Exp $ 4 | ------------------------------------------------------------------------------- 5 | 6 | local require, pairs, string = require, pairs, string 7 | 8 | local util = require "luadoc.util" 9 | 10 | logger = {} 11 | 12 | module ("luadoc") 13 | 14 | ------------------------------------------------------------------------------- 15 | -- LuaDoc version number. 16 | 17 | _COPYRIGHT = "Copyright (c) 2003-2007 The Kepler Project" 18 | _DESCRIPTION = "Documentation Generator Tool for the Lua language" 19 | _VERSION = "LuaDoc 3.0.1" 20 | 21 | ------------------------------------------------------------------------------- 22 | -- Main function 23 | -- @see luadoc.doclet.html, luadoc.doclet.formatter, luadoc.doclet.raw 24 | -- @see luadoc.taglet.standard 25 | 26 | function main (files, options) 27 | logger = util.loadlogengine(options) 28 | 29 | -- load config file 30 | if options.config ~= nil then 31 | -- load specified config file 32 | dofile(options.config) 33 | else 34 | -- load default config file 35 | require("luadoc.config") 36 | end 37 | 38 | local taglet = require(options.taglet) 39 | local doclet = require(options.doclet) 40 | 41 | -- fix bad windows paths (mix of / and \ in a path) 42 | -- standardize on forward slash 43 | if util.iswindows then 44 | for k, v in pairs(files) do 45 | files[k] = string.gsub(v, "\\", "/") 46 | end 47 | end 48 | 49 | -- analyze input 50 | taglet.options = options 51 | taglet.logger = logger 52 | local doc = taglet.start(files) 53 | 54 | -- generate output 55 | doclet.options = options 56 | doclet.logger = logger 57 | doclet.start(doc) 58 | end 59 | -------------------------------------------------------------------------------- /src/luadoc/lp.lua: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------------------- 2 | -- Lua Pages Template Preprocessor. 3 | -- 4 | -- @release $Id: lp.lua,v 1.7 2007/04/18 14:28:39 tomas Exp $ 5 | ---------------------------------------------------------------------------- 6 | 7 | local assert, error, getfenv, loadstring, setfenv = assert, error, getfenv, loadstring, setfenv 8 | local find, format, gsub, strsub = string.find, string.format, string.gsub, string.sub 9 | local concat, tinsert = table.concat, table.insert 10 | local open = io.open 11 | 12 | module (...) 13 | 14 | ---------------------------------------------------------------------------- 15 | -- function to do output 16 | local outfunc = "io.write" 17 | -- accepts the old expression field: `$| |$' 18 | local compatmode = true 19 | 20 | -- 21 | -- Builds a piece of Lua code which outputs the (part of the) given string. 22 | -- @param s String. 23 | -- @param i Number with the initial position in the string. 24 | -- @param f Number with the final position in the string (default == -1). 25 | -- @return String with the correspondent Lua code which outputs the part of the string. 26 | -- 27 | local function out (s, i, f) 28 | s = strsub(s, i, f or -1) 29 | if s == "" then return s end 30 | -- we could use `%q' here, but this way we have better control 31 | s = gsub(s, "([\\\n\'])", "\\%1") 32 | -- substitute '\r' by '\'+'r' and let `loadstring' reconstruct it 33 | s = gsub(s, "\r", "\\r") 34 | return format(" %s('%s'); ", outfunc, s) 35 | end 36 | 37 | 38 | ---------------------------------------------------------------------------- 39 | -- Translate the template to Lua code. 40 | -- @param s String to translate. 41 | -- @return String with translated code. 42 | ---------------------------------------------------------------------------- 43 | function translate (s) 44 | if compatmode then 45 | s = gsub(s, "$|(.-)|%$", "") 46 | s = gsub(s, "", "") 47 | end 48 | s = gsub(s, "<%%(.-)%%>", "") 49 | local res = {} 50 | local start = 1 -- start of untranslated part in `s' 51 | while true do 52 | local ip, fp, target, exp, code = find(s, "<%?(%w*)[ \t]*(=?)(.-)%?>", start) 53 | if not ip then break end 54 | tinsert(res, out(s, start, ip-1)) 55 | if target ~= "" and target ~= "lua" then 56 | -- not for Lua; pass whole instruction to the output 57 | tinsert(res, out(s, ip, fp)) 58 | else 59 | if exp == "=" then -- expression? 60 | tinsert(res, format(" %s(%s);", outfunc, code)) 61 | else -- command 62 | tinsert(res, format(" %s ", code)) 63 | end 64 | end 65 | start = fp + 1 66 | end 67 | tinsert(res, out(s, start)) 68 | return concat(res) 69 | end 70 | 71 | 72 | ---------------------------------------------------------------------------- 73 | -- Defines the name of the output function. 74 | -- @param f String with the name of the function which produces output. 75 | 76 | function setoutfunc (f) 77 | outfunc = f 78 | end 79 | 80 | ---------------------------------------------------------------------------- 81 | -- Turns on or off the compatibility with old CGILua 3.X behavior. 82 | -- @param c Boolean indicating if the compatibility mode should be used. 83 | 84 | function setcompatmode (c) 85 | compatmode = c 86 | end 87 | 88 | ---------------------------------------------------------------------------- 89 | -- Internal compilation cache. 90 | 91 | local cache = {} 92 | 93 | ---------------------------------------------------------------------------- 94 | -- Translates a template into a Lua function. 95 | -- Does NOT execute the resulting function. 96 | -- Uses a cache of templates. 97 | -- @param string String with the template to be translated. 98 | -- @param chunkname String with the name of the chunk, for debugging purposes. 99 | -- @return Function with the resulting translation. 100 | 101 | function compile (string, chunkname) 102 | local f, err = cache[string] 103 | if f then return f end 104 | f, err = loadstring (translate (string), chunkname) 105 | if not f then error (err, 3) end 106 | cache[string] = f 107 | return f 108 | end 109 | 110 | ---------------------------------------------------------------------------- 111 | -- Translates and executes a template in a given file. 112 | -- The translation creates a Lua function which will be executed in an 113 | -- optionally given environment. 114 | -- @param filename String with the name of the file containing the template. 115 | -- @param env Table with the environment to run the resulting function. 116 | 117 | function include (filename, env) 118 | -- read the whole contents of the file 119 | local fh = assert (open (filename)) 120 | local src = fh:read("*a") 121 | fh:close() 122 | -- translates the file into a function 123 | local prog = compile (src, '@'..filename) 124 | local _env 125 | if env then 126 | _env = getfenv (prog) 127 | setfenv (prog, env) 128 | end 129 | prog () 130 | end 131 | -------------------------------------------------------------------------------- /src/luadoc/taglet/standard.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- @release $Id: standard.lua,v 1.39 2007/12/21 17:50:48 tomas Exp $ 3 | ------------------------------------------------------------------------------- 4 | 5 | local assert, pairs, tostring, type = assert, pairs, tostring, type 6 | local io = require "io" 7 | local lfs = require "lfs" 8 | local luadoc = require "luadoc" 9 | local util = require "luadoc.util" 10 | local tags = require "luadoc.taglet.standard.tags" 11 | local string = require "string" 12 | local table = require "table" 13 | 14 | module 'luadoc.taglet.standard' 15 | 16 | ------------------------------------------------------------------------------- 17 | -- Creates an iterator for an array base on a class type. 18 | -- @param t array to iterate over 19 | -- @param class name of the class to iterate over 20 | 21 | function class_iterator (t, class) 22 | return function () 23 | local i = 1 24 | return function () 25 | while t[i] and t[i].class ~= class do 26 | i = i + 1 27 | end 28 | local v = t[i] 29 | i = i + 1 30 | return v 31 | end 32 | end 33 | end 34 | 35 | -- Patterns for function recognition 36 | local identifiers_list_pattern = "%s*(.-)%s*" 37 | local identifier_pattern = "[^%(%s]+" 38 | local function_patterns = { 39 | "^()%s*function%s*("..identifier_pattern..")%s*%("..identifiers_list_pattern.."%)", 40 | "^%s*(local%s)%s*function%s*("..identifier_pattern..")%s*%("..identifiers_list_pattern.."%)", 41 | "^()%s*("..identifier_pattern..")%s*%=%s*function%s*%("..identifiers_list_pattern.."%)", 42 | } 43 | 44 | ------------------------------------------------------------------------------- 45 | -- Checks if the line contains a function definition 46 | -- @param line string with line text 47 | -- @return function information or nil if no function definition found 48 | 49 | local function check_function (line) 50 | line = util.trim(line) 51 | 52 | local info = table.foreachi(function_patterns, function (_, pattern) 53 | local r, _, l, id, param = string.find(line, pattern) 54 | if r ~= nil then 55 | return { 56 | name = id, 57 | private = (l == "local"), 58 | param = util.split("%s*,%s*", param), 59 | } 60 | end 61 | end) 62 | 63 | -- TODO: remove these assert's? 64 | if info ~= nil then 65 | assert(info.name, "function name undefined") 66 | assert(info.param, string.format("undefined parameter list for function `%s'", info.name)) 67 | end 68 | 69 | return info 70 | end 71 | 72 | ------------------------------------------------------------------------------- 73 | -- Checks if the line contains a module definition. 74 | -- @param line string with line text 75 | -- @param currentmodule module already found, if any 76 | -- @return the name of the defined module, or nil if there is no module 77 | -- definition 78 | 79 | local function check_module (line, currentmodule) 80 | line = util.trim(line) 81 | 82 | -- module"x.y" 83 | -- module'x.y' 84 | -- module[[x.y]] 85 | -- module("x.y") 86 | -- module('x.y') 87 | -- module([[x.y]]) 88 | -- module(...) 89 | 90 | local r, _, modulename = string.find(line, "^module%s*[%s\"'(%[]+([^,\"')%]]+)") 91 | if r then 92 | -- found module definition 93 | logger:debug(string.format("found module `%s'", modulename)) 94 | return modulename 95 | end 96 | return currentmodule 97 | end 98 | 99 | ------------------------------------------------------------------------------- 100 | -- Extracts summary information from a description. The first sentence of each 101 | -- doc comment should be a summary sentence, containing a concise but complete 102 | -- description of the item. It is important to write crisp and informative 103 | -- initial sentences that can stand on their own 104 | -- @param description text with item description 105 | -- @return summary string or nil if description is nil 106 | 107 | local function parse_summary (description) 108 | -- summary is never nil... 109 | description = description or "" 110 | 111 | -- append an " " at the end to make the pattern work in all cases 112 | description = description.." " 113 | 114 | -- read until the first period followed by a space or tab 115 | local summary = string.match(description, "(.-%.)[%s\t]") 116 | 117 | -- if pattern did not find the first sentence, summary is the whole description 118 | summary = summary or description 119 | 120 | return summary 121 | end 122 | 123 | ------------------------------------------------------------------------------- 124 | -- @param f file handle 125 | -- @param line current line being parsed 126 | -- @param modulename module already found, if any 127 | -- @return current line 128 | -- @return code block 129 | -- @return modulename if found 130 | 131 | local function parse_code (f, line, modulename) 132 | local code = {} 133 | while line ~= nil do 134 | if string.find(line, "^[\t ]*%-%-%-") then 135 | -- reached another luadoc block, end this parsing 136 | return line, code, modulename 137 | else 138 | -- look for a module definition 139 | modulename = check_module(line, modulename) 140 | 141 | table.insert(code, line) 142 | line = f:read() 143 | end 144 | end 145 | -- reached end of file 146 | return line, code, modulename 147 | end 148 | 149 | ------------------------------------------------------------------------------- 150 | -- Parses the information inside a block comment 151 | -- @param block block with comment field 152 | -- @return block parameter 153 | 154 | local function parse_comment (block, first_line) 155 | 156 | -- get the first non-empty line of code 157 | local code = table.foreachi(block.code, function(_, line) 158 | if not util.line_empty(line) then 159 | -- `local' declarations are ignored in two cases: 160 | -- when the `nolocals' option is turned on; and 161 | -- when the first block of a file is parsed (this is 162 | -- necessary to avoid confusion between the top 163 | -- local declarations and the `module' definition. 164 | if (options.nolocals or first_line) and line:find"^%s*local" then 165 | return 166 | end 167 | return line 168 | end 169 | end) 170 | 171 | -- parse first line of code 172 | if code ~= nil then 173 | local func_info = check_function(code) 174 | local module_name = check_module(code) 175 | if func_info then 176 | block.class = "function" 177 | block.name = func_info.name 178 | block.param = func_info.param 179 | block.private = func_info.private 180 | elseif module_name then 181 | block.class = "module" 182 | block.name = module_name 183 | block.param = {} 184 | else 185 | block.param = {} 186 | end 187 | else 188 | -- TODO: comment without any code. Does this means we are dealing 189 | -- with a file comment? 190 | end 191 | 192 | -- parse @ tags 193 | local currenttag = "description" 194 | local currenttext -- trimmed and concatenated lines 195 | local ocurrenttext -- concatenated lines with linebreaks (eg. original non-stripped text format) 196 | local currenttagpostfix -- postfix '#' for current tag 197 | 198 | table.foreachi(block.comment, function (_, line) 199 | tline = util.trim_comment(line) 200 | oline = util.no_trim_comment(line) 201 | 202 | local r, _, tag, tagpostfix, text = string.find(tline, "@([_%w%.]+)(#?)%s+(.*)") 203 | if r ~= nil then 204 | -- found new tag, add previous one, and start a new one 205 | -- TODO: what to do with invalid tags? issue an error? or log a warning? 206 | tags.handle(currenttag, block, currenttext) 207 | 208 | currenttag = tag 209 | currenttext = text 210 | ocurrenttext = text 211 | currenttagpostfix = tagpostfix 212 | else 213 | currenttext = util.concat(currenttext, tline) 214 | ocurrenttext = util.no_concat(ocurrenttext, oline) 215 | assert(string.sub(currenttext, 1, 1) ~= " ", string.format("`%s', `%s'", currenttext, tline)) 216 | end 217 | end) 218 | if currenttagpostfix == "#" then 219 | tags.handle(currenttag, block, ocurrenttext) -- dispatch text with original linebreaks and indentations 220 | else 221 | tags.handle(currenttag, block, currenttext) -- dispatch text with trimmed and concatenated 222 | end 223 | 224 | -- extracts summary information from the description 225 | block.summary = parse_summary(block.description) 226 | assert(string.sub(block.description, 1, 1) ~= " ", string.format("`%s'", block.description)) 227 | 228 | return block 229 | end 230 | 231 | ------------------------------------------------------------------------------- 232 | -- Parses a block of comment, started with ---. Read until the next block of 233 | -- comment. 234 | -- @param f file handle 235 | -- @param line being parsed 236 | -- @param modulename module already found, if any 237 | -- @return line 238 | -- @return block parsed 239 | -- @return modulename if found 240 | 241 | local function parse_block (f, line, modulename, first) 242 | local block = { 243 | comment = {}, 244 | code = {}, 245 | } 246 | 247 | while line ~= nil do 248 | if string.find(line, "^[\t ]*%-%-") == nil then 249 | -- reached end of comment, read the code below it 250 | -- TODO: allow empty lines 251 | line, block.code, modulename = parse_code(f, line, modulename) 252 | 253 | -- parse information in block comment 254 | block = parse_comment(block, first) 255 | 256 | return line, block, modulename 257 | else 258 | table.insert(block.comment, line) 259 | line = f:read() 260 | end 261 | end 262 | -- reached end of file 263 | 264 | -- parse information in block comment 265 | block = parse_comment(block, first) 266 | 267 | return line, block, modulename 268 | end 269 | 270 | ------------------------------------------------------------------------------- 271 | -- Parses a file documented following luadoc format. 272 | -- @param filepath full path of file to parse 273 | -- @param doc table with documentation 274 | -- @return table with documentation 275 | 276 | function parse_file (filepath, doc) 277 | local blocks = {} 278 | local modulename = nil 279 | 280 | -- read each line 281 | local f = io.open(filepath, "r") 282 | local i = 1 283 | local line = f:read() 284 | local first = true 285 | while line ~= nil do 286 | if string.find(line, "^[\t ]*%-%-%-") then 287 | -- reached a luadoc block 288 | local block 289 | line, block, modulename = parse_block(f, line, modulename, first) 290 | table.insert(blocks, block) 291 | else 292 | -- look for a module definition 293 | modulename = check_module(line, modulename) 294 | 295 | -- TODO: keep beginning of file somewhere 296 | 297 | line = f:read() 298 | end 299 | first = false 300 | i = i + 1 301 | end 302 | f:close() 303 | -- store blocks in file hierarchy 304 | assert(doc.files[filepath] == nil, string.format("doc for file `%s' already defined", filepath)) 305 | table.insert(doc.files, filepath) 306 | doc.files[filepath] = { 307 | type = "file", 308 | name = filepath, 309 | doc = blocks, 310 | -- functions = class_iterator(blocks, "function"), 311 | -- tables = class_iterator(blocks, "table"), 312 | } 313 | -- 314 | local first = doc.files[filepath].doc[1] 315 | if first and modulename then 316 | doc.files[filepath].author = first.author 317 | doc.files[filepath].copyright = first.copyright 318 | doc.files[filepath].description = first.description 319 | doc.files[filepath].release = first.release 320 | doc.files[filepath].summary = first.summary 321 | end 322 | 323 | -- if module definition is found, store in module hierarchy 324 | if modulename ~= nil then 325 | if modulename == "..." then 326 | modulename = string.gsub (filepath, "%.lua$", "") 327 | modulename = string.gsub (modulename, "/", ".") 328 | end 329 | if doc.modules[modulename] ~= nil then 330 | -- module is already defined, just add the blocks 331 | table.foreachi(blocks, function (_, v) 332 | table.insert(doc.modules[modulename].doc, v) 333 | end) 334 | else 335 | -- TODO: put this in a different module 336 | table.insert(doc.modules, modulename) 337 | doc.modules[modulename] = { 338 | type = "module", 339 | name = modulename, 340 | doc = blocks, 341 | -- functions = class_iterator(blocks, "function"), 342 | -- tables = class_iterator(blocks, "table"), 343 | author = first and first.author, 344 | copyright = first and first.copyright, 345 | description = "", 346 | release = first and first.release, 347 | summary = "", 348 | } 349 | 350 | -- find module description 351 | for m in class_iterator(blocks, "module")() do 352 | doc.modules[modulename].description = util.concat( 353 | doc.modules[modulename].description, 354 | m.description) 355 | doc.modules[modulename].summary = util.concat( 356 | doc.modules[modulename].summary, 357 | m.summary) 358 | if m.author then 359 | doc.modules[modulename].author = m.author 360 | end 361 | if m.copyright then 362 | doc.modules[modulename].copyright = m.copyright 363 | end 364 | if m.release then 365 | doc.modules[modulename].release = m.release 366 | end 367 | if m.name then 368 | doc.modules[modulename].name = m.name 369 | end 370 | end 371 | doc.modules[modulename].description = doc.modules[modulename].description or (first and first.description) or "" 372 | doc.modules[modulename].summary = doc.modules[modulename].summary or (first and first.summary) or "" 373 | end 374 | 375 | -- make functions table 376 | doc.modules[modulename].functions = {} 377 | for f in class_iterator(blocks, "function")() do 378 | table.insert(doc.modules[modulename].functions, f.name) 379 | doc.modules[modulename].functions[f.name] = f 380 | end 381 | 382 | -- make tables table 383 | doc.modules[modulename].tables = {} 384 | for t in class_iterator(blocks, "table")() do 385 | table.insert(doc.modules[modulename].tables, t.name) 386 | doc.modules[modulename].tables[t.name] = t 387 | end 388 | end 389 | 390 | -- make functions table 391 | doc.files[filepath].functions = {} 392 | for f in class_iterator(blocks, "function")() do 393 | table.insert(doc.files[filepath].functions, f.name) 394 | doc.files[filepath].functions[f.name] = f 395 | end 396 | 397 | -- make tables table 398 | doc.files[filepath].tables = {} 399 | for t in class_iterator(blocks, "table")() do 400 | table.insert(doc.files[filepath].tables, t.name) 401 | doc.files[filepath].tables[t.name] = t 402 | end 403 | 404 | return doc 405 | end 406 | 407 | ------------------------------------------------------------------------------- 408 | -- Checks if the file is terminated by ".lua" or ".luadoc" and calls the 409 | -- function that does the actual parsing 410 | -- @param filepath full path of the file to parse 411 | -- @param doc table with documentation 412 | -- @return table with documentation 413 | -- @see parse_file 414 | 415 | function file (filepath, doc) 416 | local patterns = { "%.lua$", "%.luadoc$" } 417 | local valid = table.foreachi(patterns, function (_, pattern) 418 | if string.find(filepath, pattern) ~= nil then 419 | return true 420 | end 421 | end) 422 | 423 | if valid then 424 | logger:info(string.format("processing file `%s'", filepath)) 425 | doc = parse_file(filepath, doc) 426 | end 427 | 428 | return doc 429 | end 430 | 431 | ------------------------------------------------------------------------------- 432 | -- Recursively iterates through a directory, parsing each file 433 | -- @param path directory to search 434 | -- @param doc table with documentation 435 | -- @return table with documentation 436 | 437 | function directory (path, doc) 438 | for f in lfs.dir(path) do 439 | local fullpath = path .. "/" .. f 440 | local attr = lfs.attributes(fullpath) 441 | assert(attr, string.format("error stating file `%s'", fullpath)) 442 | 443 | if attr.mode == "file" then 444 | doc = file(fullpath, doc) 445 | elseif attr.mode == "directory" and f ~= "." and f ~= ".." then 446 | doc = directory(fullpath, doc) 447 | end 448 | end 449 | return doc 450 | end 451 | 452 | -- Recursively sorts the documentation table 453 | local function recsort (tab) 454 | table.sort (tab) 455 | -- sort list of functions by name alphabetically 456 | for f, doc in pairs(tab) do 457 | if doc.functions then 458 | table.sort(doc.functions) 459 | end 460 | if doc.tables then 461 | table.sort(doc.tables) 462 | end 463 | end 464 | end 465 | 466 | ------------------------------------------------------------------------------- 467 | 468 | function start (files, doc) 469 | assert(files, "file list not specified") 470 | 471 | -- Create an empty document, or use the given one 472 | doc = doc or { 473 | files = {}, 474 | modules = {}, 475 | } 476 | assert(doc.files, "undefined `files' field") 477 | assert(doc.modules, "undefined `modules' field") 478 | 479 | table.foreachi(files, function (_, path) 480 | local attr = lfs.attributes(path) 481 | assert(attr, string.format("error stating path `%s'", path)) 482 | 483 | if attr.mode == "file" then 484 | doc = file(path, doc) 485 | elseif attr.mode == "directory" then 486 | doc = directory(path, doc) 487 | end 488 | end) 489 | 490 | -- order arrays alphabetically 491 | recsort(doc.files) 492 | recsort(doc.modules) 493 | 494 | return doc 495 | end 496 | -------------------------------------------------------------------------------- /src/luadoc/taglet/standard/tags.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Handlers for several tags 3 | -- @release $Id: tags.lua,v 1.8 2007/09/05 12:39:09 tomas Exp $ 4 | ------------------------------------------------------------------------------- 5 | 6 | local luadoc = require "luadoc" 7 | local util = require "luadoc.util" 8 | local string = require "string" 9 | local table = require "table" 10 | local assert, type, tostring = assert, type, tostring 11 | 12 | module "luadoc.taglet.standard.tags" 13 | 14 | ------------------------------------------------------------------------------- 15 | 16 | local function author (tag, block, text) 17 | block[tag] = block[tag] or {} 18 | if not text then 19 | luadoc.logger:warn("author `name' not defined [["..text.."]]: skipping") 20 | return 21 | end 22 | table.insert (block[tag], text) 23 | end 24 | 25 | ------------------------------------------------------------------------------- 26 | -- Set the class of a comment block. Classes can be "module", "function", 27 | -- "table". The first two classes are automatic, extracted from the source code 28 | 29 | local function class (tag, block, text) 30 | block[tag] = text 31 | end 32 | 33 | ------------------------------------------------------------------------------- 34 | 35 | local function copyright (tag, block, text) 36 | block[tag] = text 37 | end 38 | 39 | ------------------------------------------------------------------------------- 40 | 41 | local function description (tag, block, text) 42 | block[tag] = text 43 | end 44 | 45 | ------------------------------------------------------------------------------- 46 | 47 | local function field (tag, block, text) 48 | if block["class"] ~= "table" then 49 | luadoc.logger:warn("documenting `field' for block that is not a `table'") 50 | end 51 | block[tag] = block[tag] or {} 52 | 53 | local _, _, name, desc = string.find(text, "^([_%w%.]+)%s+(.*)") 54 | assert(name, "field name not defined") 55 | 56 | table.insert(block[tag], name) 57 | block[tag][name] = desc 58 | end 59 | 60 | ------------------------------------------------------------------------------- 61 | -- Set the name of the comment block. If the block already has a name, issue 62 | -- an error and do not change the previous value 63 | 64 | local function name (tag, block, text) 65 | if block[tag] and block[tag] ~= text then 66 | luadoc.logger:error(string.format("block name conflict: `%s' -> `%s'", block[tag], text)) 67 | end 68 | 69 | block[tag] = text 70 | end 71 | 72 | ------------------------------------------------------------------------------- 73 | -- Processes a parameter documentation. 74 | -- @param tag String with the name of the tag (it must be "param" always). 75 | -- @param block Table with previous information about the block. 76 | -- @param text String with the current line beeing processed. 77 | 78 | local function param (tag, block, text) 79 | block[tag] = block[tag] or {} 80 | -- TODO: make this pattern more flexible, accepting empty descriptions 81 | local _, _, name, desc = string.find(text, "^([_%w%.]+)%s+(.*)") 82 | if not name then 83 | luadoc.logger:warn("parameter `name' not defined [["..text.."]]: skipping") 84 | return 85 | end 86 | local i = table.foreachi(block[tag], function (i, v) 87 | if v == name then 88 | return i 89 | end 90 | end) 91 | if i == nil then 92 | luadoc.logger:warn(string.format("documenting undefined parameter `%s'", name)) 93 | table.insert(block[tag], name) 94 | end 95 | block[tag][name] = desc 96 | end 97 | 98 | ------------------------------------------------------------------------------- 99 | 100 | local function release (tag, block, text) 101 | block[tag] = text 102 | end 103 | 104 | ------------------------------------------------------------------------------- 105 | 106 | local function ret (tag, block, text) 107 | tag = "ret" 108 | if type(block[tag]) == "string" then 109 | block[tag] = { block[tag], text } 110 | elseif type(block[tag]) == "table" then 111 | table.insert(block[tag], text) 112 | else 113 | block[tag] = text 114 | end 115 | end 116 | 117 | ------------------------------------------------------------------------------- 118 | -- @see ret 119 | 120 | local function see (tag, block, text) 121 | -- see is always an array 122 | block[tag] = block[tag] or {} 123 | 124 | -- remove trailing "." 125 | text = string.gsub(text, "(.*)%.$", "%1") 126 | 127 | local s = util.split("%s*,%s*", text) 128 | 129 | table.foreachi(s, function (_, v) 130 | table.insert(block[tag], v) 131 | end) 132 | end 133 | 134 | ------------------------------------------------------------------------------- 135 | -- @see ret 136 | 137 | local function usage (tag, block, text) 138 | if type(block[tag]) == "string" then 139 | block[tag] = { block[tag], text } 140 | elseif type(block[tag]) == "table" then 141 | table.insert(block[tag], text) 142 | else 143 | block[tag] = text 144 | end 145 | end 146 | 147 | ------------------------------------------------------------------------------- 148 | 149 | local handlers = {} 150 | handlers["author"] = author 151 | handlers["class"] = class 152 | handlers["copyright"] = copyright 153 | handlers["description"] = description 154 | handlers["field"] = field 155 | handlers["name"] = name 156 | handlers["param"] = param 157 | handlers["release"] = release 158 | handlers["return"] = ret 159 | handlers["see"] = see 160 | handlers["usage"] = usage 161 | 162 | ------------------------------------------------------------------------------- 163 | 164 | function handle (tag, block, text) 165 | if not handlers[tag] then 166 | luadoc.logger:error(string.format("undefined handler for tag `%s'", tag)) 167 | return 168 | end 169 | -- assert(handlers[tag], string.format("undefined handler for tag `%s'", tag)) 170 | return handlers[tag](tag, block, text) 171 | end 172 | -------------------------------------------------------------------------------- /src/luadoc/util.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- General utilities. 3 | -- @release $Id: util.lua,v 1.16 2008/02/17 06:42:51 jasonsantos Exp $ 4 | ------------------------------------------------------------------------------- 5 | 6 | local lfs = require "lfs" 7 | local type, table, string, io, assert, tostring, setmetatable, pcall = type, table, string, io, assert, tostring, setmetatable, pcall 8 | 9 | ------------------------------------------------------------------------------- 10 | -- Module with several utilities that could not fit in a specific module 11 | 12 | module "luadoc.util" 13 | 14 | ------------------------------------------------------------------------------- 15 | -- Removes spaces from the begining and end of a given string 16 | -- @param s string to be trimmed 17 | -- @return trimmed string 18 | 19 | function trim (s) 20 | return (string.gsub(s, "^%s*(.-)%s*$", "%1")) 21 | end 22 | 23 | ------------------------------------------------------------------------------- 24 | -- Removes spaces from the begining and end of a given string, considering the 25 | -- string is inside a lua comment. 26 | -- @param s string to be trimmed 27 | -- @return trimmed string 28 | -- @see trim 29 | -- @see string.gsub 30 | 31 | function trim_comment (s) 32 | s = string.gsub(s, "%-%-+(.*)$", "%1") 33 | return trim(s) 34 | end 35 | 36 | ------------------------------------------------------------------------------- 37 | -- Checks if a given line is empty 38 | -- @param line string with a line 39 | -- @return true if line is empty, false otherwise 40 | 41 | function line_empty (line) 42 | return (string.len(trim(line)) == 0) 43 | end 44 | 45 | ------------------------------------------------------------------------------- 46 | -- Appends two string, but if the first one is nil, use to second one 47 | -- @param str1 first string, can be nil 48 | -- @param str2 second string 49 | -- @return str1 .. " " .. str2, or str2 if str1 is nil 50 | 51 | function concat (str1, str2) 52 | if str1 == nil or string.len(str1) == 0 then 53 | return str2 54 | else 55 | return str1 .. " " .. str2 56 | end 57 | end 58 | 59 | ------------------------------------------------------------------------------- 60 | -- Split text into a list consisting of the strings in text, 61 | -- separated by strings matching delim (which may be a pattern). 62 | -- @param delim if delim is "" then action is the same as %s+ except that 63 | -- field 1 may be preceeded by leading whitespace 64 | -- @usage split(",%s*", "Anna, Bob, Charlie,Dolores") 65 | -- @usage split(""," x y") gives {"x","y"} 66 | -- @usage split("%s+"," x y") gives {"", "x","y"} 67 | -- @return array with strings 68 | -- @see table.concat 69 | 70 | function split(delim, text) 71 | local list = {} 72 | if string.len(text) > 0 then 73 | delim = delim or "" 74 | local pos = 1 75 | -- if delim matches empty string then it would give an endless loop 76 | if string.find("", delim, 1) and delim ~= "" then 77 | error("delim matches empty string!") 78 | end 79 | local first, last 80 | while 1 do 81 | if delim ~= "" then 82 | first, last = string.find(text, delim, pos) 83 | else 84 | first, last = string.find(text, "%s+", pos) 85 | if first == 1 then 86 | pos = last+1 87 | first, last = string.find(text, "%s+", pos) 88 | end 89 | end 90 | if first then -- found? 91 | table.insert(list, string.sub(text, pos, first-1)) 92 | pos = last+1 93 | else 94 | table.insert(list, string.sub(text, pos)) 95 | break 96 | end 97 | end 98 | end 99 | return list 100 | end 101 | 102 | ------------------------------------------------------------------------------- 103 | -- Comments a paragraph. 104 | -- @param text text to comment with "--", may contain several lines 105 | -- @return commented text 106 | 107 | function comment (text) 108 | text = string.gsub(text, "\n", "\n-- ") 109 | return "-- " .. text 110 | end 111 | 112 | ------------------------------------------------------------------------------- 113 | -- Wrap a string into a paragraph. 114 | -- @param s string to wrap 115 | -- @param w width to wrap to [80] 116 | -- @param i1 indent of first line [0] 117 | -- @param i2 indent of subsequent lines [0] 118 | -- @return wrapped paragraph 119 | 120 | function wrap(s, w, i1, i2) 121 | w = w or 80 122 | i1 = i1 or 0 123 | i2 = i2 or 0 124 | assert(i1 < w and i2 < w, "the indents must be less than the line width") 125 | s = string.rep(" ", i1) .. s 126 | local lstart, len = 1, string.len(s) 127 | while len - lstart > w do 128 | local i = lstart + w 129 | while i > lstart and string.sub(s, i, i) ~= " " do i = i - 1 end 130 | local j = i 131 | while j > lstart and string.sub(s, j, j) == " " do j = j - 1 end 132 | s = string.sub(s, 1, j) .. "\n" .. string.rep(" ", i2) .. 133 | string.sub(s, i + 1, -1) 134 | local change = i2 + 1 - (i - j) 135 | lstart = j + change 136 | len = len + change 137 | end 138 | return s 139 | end 140 | 141 | ------------------------------------------------------------------------------- 142 | -- Opens a file, creating the directories if necessary 143 | -- @param filename full path of the file to open (or create) 144 | -- @param mode mode of opening 145 | -- @return file handle 146 | 147 | function lfs.open (filename, mode) 148 | local f = io.open(filename, mode) 149 | if f == nil then 150 | filename = string.gsub(filename, "\\", "/") 151 | local dir = "" 152 | for d in string.gfind(filename, ".-/") do 153 | dir = dir .. d 154 | lfs.mkdir(dir) 155 | end 156 | f = io.open(filename, mode) 157 | end 158 | return f 159 | end 160 | 161 | 162 | ---------------------------------------------------------------------------------- 163 | -- Creates a Logger with LuaLogging, if present. Otherwise, creates a mock logger. 164 | -- @param options a table with options for the logging mechanism 165 | -- @return logger object that will implement log methods 166 | 167 | function loadlogengine(options) 168 | local logenabled = pcall(function() 169 | require "logging" 170 | require "logging.console" 171 | end) 172 | 173 | local logging = logenabled and logging 174 | 175 | if logenabled then 176 | if options.filelog then 177 | logger = logging.file("luadoc.log") -- use this to get a file log 178 | else 179 | logger = logging.console("[%level] %message\n") 180 | end 181 | 182 | if options.verbose then 183 | logger:setLevel(logging.INFO) 184 | else 185 | logger:setLevel(logging.WARN) 186 | end 187 | 188 | else 189 | noop = {__index=function(...) 190 | return function(...) 191 | -- noop 192 | end 193 | end} 194 | 195 | logger = {} 196 | setmetatable(logger, noop) 197 | end 198 | 199 | return logger 200 | end 201 | 202 | ------------------------------------------------------------------------------- 203 | -- Check if the current executing platform is windows 204 | -- @return true if execution platform is windows 205 | function iswindows() 206 | return string.find(_G.package.config:sub(1,1), "\\") 207 | end 208 | 209 | ------------------------------------------------------------------------------- 210 | -- Removes comment markers from the beginning of a string, leaves spaces alone. 211 | -- @param s string to be trimmed 212 | -- @return trimmed string 213 | -- @see trim_comment 214 | 215 | function no_trim_comment (s) 216 | s = string.gsub(trim(s), "%-%-+ (.*)$", "%1") 217 | return s 218 | end 219 | 220 | ------------------------------------------------------------------------------- 221 | -- Appends two strings using original line-end, but if the first one is nil, use to second one. 222 | -- to be used when using the text without removal of line ends and indentation 223 | -- @param str1 first string, can be nil 224 | -- @param str2 second string 225 | -- @return str1 .. "\n" .. str2, or str2 if str1 is nil 226 | 227 | function no_concat (str1, str2) 228 | if str1 == nil or string.len(str1) == 0 then 229 | return str2 230 | else 231 | return str1 .. "\n" .. str2 232 | end 233 | end 234 | -------------------------------------------------------------------------------- /test/trailing_hash_test.lua: -------------------------------------------------------------------------------- 1 | -- Run LuaDoc on this file to test the results of the tag-trailing '#' 2 | 3 | -------------------------- 4 | -- Usage tag should be the original usage tag, concatenated and trimmed 5 | -- @usage for k,v in pairs(sometable) do 6 | -- print(k,v) 7 | -- end 8 | function JustATest() 9 | end 10 | 11 | -------------------------- 12 | -- Usage tag includes trailing '#', should be the new format, not trimmed and linebreaks retained 13 | -- @usage# for k,v in pairs(sometable) do 14 | -- print(k,v) 15 | -- end 16 | function JustAnotherTest() 17 | end 18 | 19 | -------------------------- 20 | -- Usage tags contains # in the middle, shouldn't be recognized as a tag 21 | -- @usage#forsome test1 22 | -- test2 23 | -- test3 24 | function JustOneLastTest() 25 | end 26 | --------------------------------------------------------------------------------