Codebase list lua-ldoc / c49fa67
more tests; styles meant as catalog of supported styles, submodule shows off within and submodule tag steve donovan 11 years ago
11 changed file(s) with 267 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
113113
114114
115115 function KindMap.add_kind (klass,tag,kind,subnames)
116 klass.types_by_tag[tag] = kind
117 klass.types_by_kind[kind] = {type=tag,subnames=subnames}
118 append(klass.kinds,kind)
116 if not klass.types_by_kind[kind] then
117 klass.types_by_tag[tag] = kind
118 klass.types_by_kind[kind] = {type=tag,subnames=subnames}
119 append(klass.kinds,kind)
120 end
119121 end
120122
121123
172174
173175
174176 function M.extract_identifier (value)
175 return value:match('([%.:%-_%w]+)')
177 return value:match('([%.:%-_%w]+)(.*)$')
176178 end
177179
178180 function M.strip (s)
2424
2525 test: test-basic test-example test-md test-tables
2626
27 # cp -r docs cdocs in these directories first...
2827 RUN=&& ldoc . && diff -r docs cdocs && echo ok
2928
3029 test-basic:
3837
3938 test-tables:
4039 cd tests && cd simple $(RUN)
40
41 test-clean: clean-basic clean-example clean-md clean-tables
42
43 CLEAN=&& ldoc . && rd /S /Q cdocs && cp -rf docs cdocs
44
45 clean-basic:
46 cd tests $(CLEAN)
47
48 clean-example:
49 cd tests && cd example $(CLEAN)
50
51 clean-md:
52 cd tests && cd md-test $(CLEAN)
53
54 clean-tables:
55 cd tests && cd simple $(CLEAN)
0 print(arg,DOOFUS)
0 --[[
1 A non-doc comment
2 multi-line
3 probably containing license information!
4 Doesn't use module(), but module name is inferred from file name
5 ]]
6 ------------
7 -- Test module,
8 -- Actual blurb here!
9 ----
10
11 local one = {}
12
13 --- answer to everything.
14 function one.answer ()
15 return 42
16 end
17
18 return one
19
20
0 --------------------------------------------------------------------------------
1 --- Queue of objects sorted by priority
2 -- @module lua-nucleo.priority_queue
3 -- This file is a part of lua-nucleo library
4 -- @copyright lua-nucleo authors (see file `COPYRIGHT` for the license)
5 --------------------------------------------------------------------------------
6
7 local arguments,
8 method_arguments
9 = import 'lua-nucleo/args.lua'
10 {
11 'arguments',
12 'method_arguments'
13 }
14
15 local lower_bound_gt
16 = import 'lua-nucleo/algorithm.lua'
17 {
18 'lower_bound_gt'
19 }
20
21 --------------------------------------------------------------------------------
22
23 local table_insert, table_remove = table.insert, table.remove
24
25 --------------------------------------------------------------------------------
26
27 --- Priority Queue
28 -- @factory priority_queue
29 local make_priority_queue
30 do
31 local PRIORITY_KEY = 1
32 local VALUE_KEY = 2
33
34 local insert = function(self, priority, value)
35 method_arguments(
36 self,
37 "number", priority
38 )
39 assert(value ~= nil, "value can't be nil") -- value may be of any type, except nil
40
41 local queue = self.queue_
42 local k = lower_bound_gt(queue, PRIORITY_KEY, priority)
43
44 table_insert(queue, k, { [PRIORITY_KEY] = priority, [VALUE_KEY] = value })
45 end
46
47 local front = function(self)
48 method_arguments(
49 self
50 )
51
52 local queue = self.queue_
53 local front_elem = queue[#queue]
54
55 if front_elem == nil then
56 return nil
57 end
58
59 return front_elem[PRIORITY_KEY], front_elem[VALUE_KEY]
60 end
61
62 --- pop last value.
63 -- @return priority
64 -- @return value
65 local pop = function(self)
66 method_arguments(
67 self
68 )
69
70 local front_elem = table_remove(self.queue_)
71
72 if front_elem == nil then
73 return nil
74 end
75
76 return front_elem[PRIORITY_KEY], front_elem[VALUE_KEY]
77 end
78
79 --- construct a @{priority_queue}.
80 -- @constructor
81 make_priority_queue = function()
82 --- @export
83 return
84 {
85 insert = insert;
86 front = front;
87 pop = pop;
88 --
89 queue_ = { };
90 }
91 end
92 end
93
94 return
95 {
96 make_priority_queue = make_priority_queue;
97 }
0 ------------
1 -- Alternative to no-magic style.
2 -- Description here
3 ----
4
5 --- answer to everything.
6 -- @return magic number
7 local function answer ()
8 return 42
9 end
10
11 --- @export
12 return {
13 answer = answer
14 }
15
16
0 ------------
1 -- Classic Lua 5.1 module,
2 -- Description here
3 ----
4
5 module 'two'
6
7 --- answer to everything.
8 function answer ()
9 return 42
10 end
11
12
0 /* First comment is ignored,
1 * containing licenses, warnings,
2 * old-fashioned commit info and so forth
3 */
4
5 /** No-brainer C extension.
6 Description as before.
7 @module x
8 */
9 #include <lua.h>
10 #include <lauxlib.h>
11 #include <lualib.h>
12
13 /***
14 @string name
15 @int age
16 @table output
17 */
18
19 /***
20 Create a table with given array and hash slots.
21 Note that we can't (yet) deduce the name of
22 the Lua function.
23 @function createtable
24 @param narr initial array slots, default 0
25 @param nrec initial hash slots, default 0
26 @return table
27 */
28 static int l_createtable (lua_State *L) {
29 int narr = luaL_optint(L,1,0);
30 int nrec = luaL_optint(L,2,0);
31 lua_createtable(L,narr,nrec);
32 return 1;
33 }
34
35 static const luaL_reg x[] = {
36 {"createtable",l_createtable},
37 {NULL,NULL}
38 };
39
40 int luaopen_x(lua_State *L)
41 {
42 luaL_register (L, "x", x);
43 return 1;
44 }
0 file = {'mylib/init.lua','mylib/extra.lua'}
1 if foo then print 'foo' end
0 -----------
1 -- Extra module
2 -- @submodule mylib
3
4 --- will appear in mylib's docs!
5 function E ()
6
7 end
8
9 --- ditto
10 function F ()
11
12 end
0 -----------
1 -- Main module.
2 -- This contains four functions, two of which are in
3 -- another section implicitly specified using the 'within' tag.
4 -- (This allows functions placed together to be classified
5 -- separately)
6 --
7 -- Furthermore, the 'mylib.extra' functions will be added
8 -- as their own section, allowing you to document a logical module
9 -- spanning several files
10 --
11 -- @module mylib
12
13 --- first.
14 function A ()
15
16 end
17
18 --- second, within its own section.
19 -- @within Utilities
20 function B ()
21
22 end
23
24 --- third.
25 function C ()
26
27 end
28
29 --- fourth, together with second.
30 -- @within Utilities
31 function D ()
32
33 end
34