2008-05-26 15:25:40 +02:00
|
|
|
#!/usr/bin/lua
|
2008-06-23 18:19:39 +02:00
|
|
|
-- Translate the custom doxygen tags in c-source to a
|
|
|
|
-- dummy lua source file that can be processed by luadoc.
|
2008-05-26 15:25:40 +02:00
|
|
|
-- Take a .c file in stdin
|
|
|
|
|
2008-06-23 18:53:45 +02:00
|
|
|
nparam = 0;
|
|
|
|
function string.replace_param(s)
|
|
|
|
nparam = nparam + 1;
|
|
|
|
return "@param arg" .. nparam
|
|
|
|
end
|
|
|
|
|
2008-06-23 18:19:39 +02:00
|
|
|
function string.comment_translate(s)
|
2008-07-02 10:32:35 +02:00
|
|
|
local lua_comment = "";
|
|
|
|
nparam = 0;
|
|
|
|
for line in s:gmatch("[^\r\n]+") do
|
|
|
|
line = line:gsub("/%*%*", "---")
|
|
|
|
line = line:gsub("^.*%*", "--")
|
|
|
|
line = line:gsub("\\lvalue", "")
|
|
|
|
line = line:gsub("\\(lparam)", string.replace_param)
|
|
|
|
line = line:gsub("\\lreturn", "@return")
|
|
|
|
line = line:gsub("\\lfield", "@field")
|
|
|
|
lua_comment = lua_comment .. line .. "\n"
|
|
|
|
end
|
|
|
|
-- remove last \n
|
|
|
|
lua_comment = lua_comment:sub(1, #lua_comment - 1)
|
2008-06-23 18:19:39 +02:00
|
|
|
return lua_comment
|
2008-05-26 15:25:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Read all the files in lines
|
|
|
|
lines = io.read("*all")
|
|
|
|
|
|
|
|
ilines = {}
|
|
|
|
|
|
|
|
-- read the lines in table `ilines'
|
|
|
|
for line in lines:gmatch("[^\r\n]+") do
|
|
|
|
table.insert(ilines, line)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Store function documentations in an array
|
|
|
|
function_doc = {}
|
|
|
|
for i, line in ipairs(ilines) do
|
|
|
|
if line:find("^/%*%*") then
|
|
|
|
comment_start = true
|
|
|
|
comment = line
|
|
|
|
elseif line:find("%*/") then
|
|
|
|
comment_start = false
|
|
|
|
local l = ilines[i + 2]
|
2008-06-26 22:43:37 +02:00
|
|
|
if l then
|
|
|
|
local fctname
|
|
|
|
_, _, fctname = l:find("^(.+)%(lua_State")
|
|
|
|
if fctname then
|
|
|
|
function_doc[fctname] = comment
|
|
|
|
end
|
2008-05-26 15:25:40 +02:00
|
|
|
end
|
|
|
|
comment = nil
|
|
|
|
elseif comment_start then
|
2008-06-26 22:43:37 +02:00
|
|
|
if not line:find("\\param") and not line:find("\\return") and not line:find("\\luastack") then
|
|
|
|
comment = comment .. "\n" .. line
|
|
|
|
end
|
2008-05-26 15:25:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-02 17:57:16 +02:00
|
|
|
|
2008-05-26 15:25:40 +02:00
|
|
|
-- Get function list and print their documentation
|
|
|
|
capture = false
|
|
|
|
for i, line in ipairs(ilines) do
|
|
|
|
if not libname then
|
2008-06-26 23:32:33 +02:00
|
|
|
_, _, libname, libtype = line:find("const struct luaL_reg awesome_(%a+)_(%a+)%[%] ")
|
2008-05-26 15:25:40 +02:00
|
|
|
-- Special case
|
|
|
|
if not libname then _, _, libname, libtype = line:find("const struct luaL_reg (awesome)_(lib)%[%] =") end
|
2008-07-02 17:57:16 +02:00
|
|
|
-- __index alone
|
|
|
|
if not libname and line:find("^luaA_.*_index") then
|
|
|
|
local fctname, fctdef
|
|
|
|
_, _, fctdef, fctname = line:find("^(luaA_(.+)_index)")
|
|
|
|
print(function_doc[fctdef]:comment_translate())
|
|
|
|
print("-- @class table")
|
|
|
|
print("-- @name " .. fctname)
|
|
|
|
print(fctname)
|
|
|
|
end
|
2008-05-26 15:25:40 +02:00
|
|
|
else
|
|
|
|
if line:find("};") then
|
|
|
|
libname = nil
|
|
|
|
else
|
|
|
|
local fctname, fctdef
|
2008-06-26 22:43:37 +02:00
|
|
|
_, _, fctname, fctdef = line:find("\"(.+)\", (.+) },?")
|
2008-07-02 10:32:35 +02:00
|
|
|
if fctname and (not fctname:find("^__")
|
2008-07-02 17:57:16 +02:00
|
|
|
or fctname:find("^__call")) then
|
2008-05-26 20:24:30 +02:00
|
|
|
if function_doc[fctdef] then
|
2008-07-02 17:57:16 +02:00
|
|
|
fctname = "." .. fctname
|
|
|
|
fctname = fctname:gsub("^.__call", "")
|
|
|
|
print(function_doc[fctdef]:comment_translate())
|
|
|
|
print("function " .. libname .. fctname .. "()")
|
|
|
|
print("end");
|
2008-05-26 20:24:30 +02:00
|
|
|
else
|
|
|
|
print("This function is not yet documented.")
|
|
|
|
end
|
2008-05-26 20:17:15 +02:00
|
|
|
print()
|
2008-05-26 15:25:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|