1
0

APIDump: Split long code into functions.

This commit is contained in:
madmaxoft 2013-10-18 20:32:36 +02:00
parent 41270dc02e
commit 778d786349
2 changed files with 110 additions and 94 deletions

View File

@ -3530,6 +3530,8 @@ end
"Initialize",
"LinkifyString",
"ListMissingPages",
"ListUndocumentedObjects",
"ListUnexportedObjects",
"ReadDescriptions",
"ReadHooks",
"WriteHtmlClass",

View File

@ -310,100 +310,9 @@ function DumpAPIHtml()
cFile:Copy(g_Plugin:GetLocalDirectory() .. "/run_prettify.js", "API/run_prettify.js");
cFile:Copy(g_Plugin:GetLocalFolder() .. "/lang-lua.js", "API/lang-lua.js");
-- List the undocumented objects:
f = io.open("API/_undocumented.lua", "w");
if (f ~= nil) then
f:write("\n-- This is the list of undocumented API objects, automatically generated by APIDump\n\n");
f:write("g_APIDesc =\n{\n\tClasses =\n\t{\n");
for i, cls in ipairs(API) do
local HasFunctions = ((cls.UndocumentedFunctions ~= nil) and (#cls.UndocumentedFunctions > 0));
local HasConstants = ((cls.UndocumentedConstants ~= nil) and (#cls.UndocumentedConstants > 0));
if (HasFunctions or HasConstants) then
f:write("\t\t" .. cls.Name .. " =\n\t\t{\n");
if ((cls.Desc == nil) or (cls.Desc == "")) then
f:write("\t\t\tDesc = \"\"\n");
end
end
if (HasFunctions) then
f:write("\t\t\tFunctions =\n\t\t\t{\n");
table.sort(cls.UndocumentedFunctions);
for j, fn in ipairs(cls.UndocumentedFunctions) do
f:write("\t\t\t\t" .. fn .. " = { Params = \"\", Return = \"\", Notes = \"\" },\n");
end -- for j, fn - cls.Undocumented[]
f:write("\t\t\t},\n\n");
end
if (HasConstants) then
f:write("\t\t\tConstants =\n\t\t\t{\n");
table.sort(cls.UndocumentedConstants);
for j, cn in ipairs(cls.UndocumentedConstants) do
f:write("\t\t\t\t" .. cn .. " = { Notes = \"\" },\n");
end -- for j, fn - cls.Undocumented[]
f:write("\t\t\t},\n\n");
end
if (HasFunctions or HasConstants) then
f:write("\t\t},\n\n");
end
end -- for i, cls - API[]
f:write("\t},\n");
if (#UndocumentedHooks > 0) then
f:write("\n\tHooks =\n\t{\n");
for i, hook in ipairs(UndocumentedHooks) do
if (i > 1) then
f:write("\n");
end
f:write("\t\t" .. hook .. " =\n\t\t{\n");
f:write("\t\t\tCalledWhen = \"\",\n");
f:write("\t\t\tDefaultFnName = \"On\", -- also used as pagename\n");
f:write("\t\t\tDesc = [[\n\t\t\t\t\n\t\t\t]],\n");
f:write("\t\t\tParams =\n\t\t\t{\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t},\n");
f:write("\t\t\tReturns = [[\n\t\t\t\t\n\t\t\t]],\n");
f:write("\t\t}, -- " .. hook .. "\n");
end
end
f:close();
end
-- List the unexported documented API objects:
f = io.open("API/_unexported-documented.txt", "w");
if (f ~= nil) then
for clsname, cls in pairs(g_APIDesc.Classes) do
if not(cls.IsExported) then
-- The whole class is not exported
f:write("class\t" .. clsname .. "\n");
else
if (cls.Functions ~= nil) then
for fnname, fnapi in pairs(cls.Functions) do
if not(fnapi.IsExported) then
f:write("func\t" .. clsname .. "." .. fnname .. "\n");
end
end -- for j, fn - cls.Functions[]
end
if (cls.Constants ~= nil) then
for cnname, cnapi in pairs(cls.Constants) do
if not(cnapi.IsExported) then
f:write("const\t" .. clsname .. "." .. cnname .. "\n");
end
end -- for j, fn - cls.Functions[]
end
end
end -- for i, cls - g_APIDesc.Classes[]
f:close();
end
-- List the missing pages
-- List the documentation problems:
ListUndocumentedObjects(API, UndocumentedHooks);
ListUnexportedObjects();
ListMissingPages();
LOG("API subfolder written");
@ -904,6 +813,111 @@ end
--- Writes a list of undocumented objects into a file
function ListUndocumentedObjects(API, UndocumentedHooks)
f = io.open("API/_undocumented.lua", "w");
if (f ~= nil) then
f:write("\n-- This is the list of undocumented API objects, automatically generated by APIDump\n\n");
f:write("g_APIDesc =\n{\n\tClasses =\n\t{\n");
for i, cls in ipairs(API) do
local HasFunctions = ((cls.UndocumentedFunctions ~= nil) and (#cls.UndocumentedFunctions > 0));
local HasConstants = ((cls.UndocumentedConstants ~= nil) and (#cls.UndocumentedConstants > 0));
if (HasFunctions or HasConstants) then
f:write("\t\t" .. cls.Name .. " =\n\t\t{\n");
if ((cls.Desc == nil) or (cls.Desc == "")) then
f:write("\t\t\tDesc = \"\"\n");
end
end
if (HasFunctions) then
f:write("\t\t\tFunctions =\n\t\t\t{\n");
table.sort(cls.UndocumentedFunctions);
for j, fn in ipairs(cls.UndocumentedFunctions) do
f:write("\t\t\t\t" .. fn .. " = { Params = \"\", Return = \"\", Notes = \"\" },\n");
end -- for j, fn - cls.Undocumented[]
f:write("\t\t\t},\n\n");
end
if (HasConstants) then
f:write("\t\t\tConstants =\n\t\t\t{\n");
table.sort(cls.UndocumentedConstants);
for j, cn in ipairs(cls.UndocumentedConstants) do
f:write("\t\t\t\t" .. cn .. " = { Notes = \"\" },\n");
end -- for j, fn - cls.Undocumented[]
f:write("\t\t\t},\n\n");
end
if (HasFunctions or HasConstants) then
f:write("\t\t},\n\n");
end
end -- for i, cls - API[]
f:write("\t},\n");
if (#UndocumentedHooks > 0) then
f:write("\n\tHooks =\n\t{\n");
for i, hook in ipairs(UndocumentedHooks) do
if (i > 1) then
f:write("\n");
end
f:write("\t\t" .. hook .. " =\n\t\t{\n");
f:write("\t\t\tCalledWhen = \"\",\n");
f:write("\t\t\tDefaultFnName = \"On\", -- also used as pagename\n");
f:write("\t\t\tDesc = [[\n\t\t\t\t\n\t\t\t]],\n");
f:write("\t\t\tParams =\n\t\t\t{\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n");
f:write("\t\t\t},\n");
f:write("\t\t\tReturns = [[\n\t\t\t\t\n\t\t\t]],\n");
f:write("\t\t}, -- " .. hook .. "\n");
end
end
f:close();
end
end
--- Lists the API objects that are documented but not available in the API:
function ListUnexportedObjects()
f = io.open("API/_unexported-documented.txt", "w");
if (f ~= nil) then
for clsname, cls in pairs(g_APIDesc.Classes) do
if not(cls.IsExported) then
-- The whole class is not exported
f:write("class\t" .. clsname .. "\n");
else
if (cls.Functions ~= nil) then
for fnname, fnapi in pairs(cls.Functions) do
if not(fnapi.IsExported) then
f:write("func\t" .. clsname .. "." .. fnname .. "\n");
end
end -- for j, fn - cls.Functions[]
end
if (cls.Constants ~= nil) then
for cnname, cnapi in pairs(cls.Constants) do
if not(cnapi.IsExported) then
f:write("const\t" .. clsname .. "." .. cnname .. "\n");
end
end -- for j, fn - cls.Functions[]
end
end
end -- for i, cls - g_APIDesc.Classes[]
f:close();
end
end
function ListMissingPages()
local MissingPages = {};
for PageName, Referrers in pairs(g_TrackedPages) do