2 -- Translate the custom doxygen tags in c-source to a
3 -- dummy lua source file that can be processed by luadoc.
4 -- Take a .c file in stdin
7 function string.replace_param(s
)
9 return "@param arg" .. nparam
12 function string.comment_translate(s
)
13 local lua_comment
= "";
15 for line
in s
:gmatch("[^\r\n]+") do
16 if not line
:match("\\lvalue") then
17 line
= line
:gsub("/%*%*", "---")
18 line
= line
:gsub("^.*%*", "--")
19 line
= line
:gsub("\\(lparam)", string.replace_param
)
20 line
= line
:gsub("\\lreturn", "@return")
21 line
= line
:gsub("\\lfield", "@field")
22 lua_comment
= lua_comment
.. line
.. "\n"
26 lua_comment
= lua_comment
:sub(1, #lua_comment
- 1)
30 -- Read all the files in lines
31 lines
= io
.read("*all")
35 -- read the lines in table `ilines'
36 for line
in lines
:gmatch("[^\r\n]+") do
37 table.insert(ilines
, line
)
40 -- Store function documentations in an array
42 for i
, line
in ipairs(ilines
) do
43 if line
:find("^/%*%*") then
46 elseif line
:find("%*/") then
48 local l
= ilines
[i
+ 2]
51 _
, _
, fctname
= l
:find("^(.+)%(lua_State")
53 function_doc
[fctname
] = comment
57 elseif comment_start
then
58 if not line
:find("\\param") and not line
:find("\\return") and not line
:find("\\luastack") then
59 comment
= comment
.. "\n" .. line
64 print("---------------------------------------------------------------------------")
65 print("--- capi: awesome C API")
67 print("-- @author Julien Danjou <julien@danjou.info>")
68 print("-- @copyright 2008 Julien Danjou")
69 print("---------------------------------------------------------------------------")
70 print("module(\"capi\")")
72 -- Get function list and print their documentation
74 for i
, line
in ipairs(ilines
) do
76 _
, _
, libname
, libtype
= line
:find("const struct luaL_reg awesome_(%a+)_(%a+)%[%] ")
78 if not libname
then _
, _
, libname
, libtype
= line
:find("const struct luaL_reg (awesome)_(lib)%[%] =") end
80 if not libname
and line
:find("^luaA_.*_index") then
82 _
, _
, fctdef
, fctname
= line
:find("^(luaA_(.+)_index)")
83 if function_doc
[fctdef
] and not fctdef
:find("_module_") then
84 print(function_doc
[fctdef
]:comment_translate())
85 print("-- @class table")
86 print("-- @name " .. fctname
)
91 if line
:find("};") then
95 _
, _
, fctname
, fctdef
= line
:find("\"(.+)\", (.+) },?")
96 if fctname
and (not fctname
:find("^__")
97 or fctname
:find("^__call")) then
98 if function_doc
[fctdef
] then
99 fctname
= "." .. fctname
100 fctname
= fctname
:gsub("^.__call", "")
101 print(function_doc
[fctdef
]:comment_translate())
102 print("function " .. libname
.. fctname
.. "()")
105 print("This function is not yet documented.")