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 line
= line
:gsub("/%*%*", "---")
17 line
= line
:gsub("^.*%*", "--")
18 line
= line
:gsub("\\lvalue", "")
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"
25 lua_comment
= lua_comment
:sub(1, #lua_comment
- 1)
29 -- Read all the files in lines
30 lines
= io
.read("*all")
34 -- read the lines in table `ilines'
35 for line
in lines
:gmatch("[^\r\n]+") do
36 table.insert(ilines
, line
)
39 -- Store function documentations in an array
41 for i
, line
in ipairs(ilines
) do
42 if line
:find("^/%*%*") then
45 elseif line
:find("%*/") then
47 local l
= ilines
[i
+ 2]
50 _
, _
, fctname
= l
:find("^(.+)%(lua_State")
52 function_doc
[fctname
] = comment
56 elseif comment_start
then
57 if not line
:find("\\param") and not line
:find("\\return") and not line
:find("\\luastack") then
58 comment
= comment
.. "\n" .. line
63 print("---------------------------------------------------------------------------")
64 print("--- capi: awesome C API")
66 print("-- @author Julien Danjou <julien@danjou.info>")
67 print("-- @copyright 2008 Julien Danjou")
68 print("---------------------------------------------------------------------------")
69 print("module(\"capi\")")
71 -- Get function list and print their documentation
73 for i
, line
in ipairs(ilines
) do
75 _
, _
, libname
, libtype
= line
:find("const struct luaL_reg awesome_(%a+)_(%a+)%[%] ")
77 if not libname
then _
, _
, libname
, libtype
= line
:find("const struct luaL_reg (awesome)_(lib)%[%] =") end
79 if not libname
and line
:find("^luaA_.*_index") then
81 _
, _
, fctdef
, fctname
= line
:find("^(luaA_(.+)_index)")
82 print(function_doc
[fctdef
]:comment_translate())
83 print("-- @class table")
84 print("-- @name " .. fctname
)
88 if line
:find("};") then
92 _
, _
, fctname
, fctdef
= line
:find("\"(.+)\", (.+) },?")
93 if fctname
and (not fctname
:find("^__")
94 or fctname
:find("^__call")) then
95 if function_doc
[fctdef
] then
96 fctname
= "." .. fctname
97 fctname
= fctname
:gsub("^.__call", "")
98 print(function_doc
[fctdef
]:comment_translate())
99 print("function " .. libname
.. fctname
.. "()")
102 print("This function is not yet documented.")