public
Description: A library of higher-order functions for Lua
Homepage: http://www.samsarin.com/blog/lua-functional
Clone URL: git://github.com/samsarin/lua-functional.git
lua-functional / doc.lua
100644 51 lines (45 sloc) 1.329 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--
-- Simple tool to generate Markdown for functional
--
 
output = assert(io.open('functional.mkd', "w"))
 
-- First pull in README
input = assert(io.open('README'))
output:write(input:read("*a"))
input:close()
 
-- Then pull in the function reference from the source
output:write("### Function Reference {#reference}\n\n")
input = assert(io.open('functional.lua'))
for line in input:lines() do
    if in_block_comment then
        s, e, m = line:find("(.-)]]")
        if s then
            line = m .. "\n"
            in_block_comment = false
        end
 
        output:write(line .. "\n")
    elseif in_single_comment then
        s, e, m = line:find("%-%-%s?(.*)")
        if s then
            buffer = buffer .. m .. "\n"
        else
            in_single_comment = false
            _, _, name = line:find("^function%s-([%w_]+)")
            if name then
                output:write("#### " .. line .. " {#" .. name .. "}\n" .. buffer .. "\n")
            end
            buffer = ""
        end
    else
        if (line:match("%-%-%[%[%[")) then
            in_block_comment = true
        else
            match = line:match("^%-%-%s?(.*)")
            if match then
                buffer = match .. "\n"
                in_single_comment = true
            end
        end
    end
end
 
input:close()
output:close()