awful.completion: doc fixes
[awesome.git] / build-utils / fake-lua-src.lua
blobfaaf65446a9947644c60e077ba69420867fe9d50
1 #!/usr/bin/lua
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
6 nparam = 0;
7 function string.replace_param(s)
8 nparam = nparam + 1;
9 return "@param arg" .. nparam
10 end
12 function string.comment_translate(s)
13 local lua_comment = "";
14 nparam = 0;
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"
23 end
24 end
25 -- remove last \n
26 lua_comment = lua_comment:sub(1, #lua_comment - 1)
27 return lua_comment
28 end
30 -- Read all the files in lines
31 lines = io.read("*all")
33 ilines = {}
35 -- read the lines in table `ilines'
36 for line in lines:gmatch("[^\r\n]+") do
37 table.insert(ilines, line)
38 end
40 -- Store function documentations in an array
41 function_doc = {}
42 for i, line in ipairs(ilines) do
43 if line:find("^/%*%*") then
44 comment_start = true
45 comment = line
46 elseif line:find("%*/") then
47 comment_start = false
48 local l = ilines[i + 2]
49 if l then
50 local fctname
51 _, _, fctname = l:find("^(.+)%(lua_State")
52 if fctname then
53 function_doc[fctname] = comment
54 end
55 end
56 comment = nil
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
60 end
61 end
62 end
64 print("---------------------------------------------------------------------------")
65 print("--- capi: awesome C API")
66 print("--")
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
73 capture = false
74 for i, line in ipairs(ilines) do
75 if not libname then
76 _, _, libname, libtype = line:find("const struct luaL_reg awesome_(%a+)_(%a+)%[%] ")
77 -- Special case
78 if not libname then _, _, libname, libtype = line:find("const struct luaL_reg (awesome)_(lib)%[%] =") end
79 -- __index alone
80 if not libname and line:find("^luaA_.*_index") then
81 local fctname, fctdef
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)
87 print(fctname)
88 end
89 end
90 else
91 if line:find("};") then
92 libname = nil
93 else
94 local fctname, fctdef
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 .. "()")
103 print("end");
104 else
105 print("This function is not yet documented.")
107 print()