client: rewrite focus()
[awesome.git] / build-utils / fake-lua-src.lua
blob4b3f3351fee9309614dcb83a1b65302c13a62ae8
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 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"
23 end
24 -- remove last \n
25 lua_comment = lua_comment:sub(1, #lua_comment - 1)
26 return lua_comment
27 end
29 -- Read all the files in lines
30 lines = io.read("*all")
32 ilines = {}
34 -- read the lines in table `ilines'
35 for line in lines:gmatch("[^\r\n]+") do
36 table.insert(ilines, line)
37 end
39 -- Store function documentations in an array
40 function_doc = {}
41 for i, line in ipairs(ilines) do
42 if line:find("^/%*%*") then
43 comment_start = true
44 comment = line
45 elseif line:find("%*/") then
46 comment_start = false
47 local l = ilines[i + 2]
48 if l then
49 local fctname
50 _, _, fctname = l:find("^(.+)%(lua_State")
51 if fctname then
52 function_doc[fctname] = comment
53 end
54 end
55 comment = nil
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
59 end
60 end
61 end
63 print("---------------------------------------------------------------------------")
64 print("--- capi: awesome C API")
65 print("--")
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
72 capture = false
73 for i, line in ipairs(ilines) do
74 if not libname then
75 _, _, libname, libtype = line:find("const struct luaL_reg awesome_(%a+)_(%a+)%[%] ")
76 -- Special case
77 if not libname then _, _, libname, libtype = line:find("const struct luaL_reg (awesome)_(lib)%[%] =") end
78 -- __index alone
79 if not libname and line:find("^luaA_.*_index") then
80 local fctname, fctdef
81 _, _, fctdef, fctname = line:find("^(luaA_(.+)_index)")
82 print(function_doc[fctdef]:comment_translate())
83 print("-- @class table")
84 print("-- @name " .. fctname)
85 print(fctname)
86 end
87 else
88 if line:find("};") then
89 libname = nil
90 else
91 local fctname, fctdef
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 .. "()")
100 print("end");
101 else
102 print("This function is not yet documented.")
104 print()