1
0

APIDump: The APIDesc from wiki can be read back by Lua.

This commit is contained in:
madmaxoft 2013-09-12 19:52:47 +02:00
parent 5b8271517d
commit e9a809dfb9

View File

@ -345,6 +345,7 @@ end
-- Only Windows-style paths are supported for now, since this is a one-time action -- Only Windows-style paths are supported for now, since this is a one-time action
function ConvertWikiToDesc() function ConvertWikiToDesc()
local fout = io.open("APIDesc.wiki.lua", "w"); local fout = io.open("APIDesc.wiki.lua", "w");
fout:write("g_APIDesc =\n{\n\tClasses =\n\t{\n");
for filename in io.popen([[dir wikipages\\api\\*.txt /b]]):lines() do for filename in io.popen([[dir wikipages\\api\\*.txt /b]]):lines() do
-- Read file -- Read file
local fin = io.open("wikipages\\api\\" .. filename, "r"); local fin = io.open("wikipages\\api\\" .. filename, "r");
@ -356,10 +357,16 @@ function ConvertWikiToDesc()
local Desc = ""; local Desc = "";
local Constants = {}; local Constants = {};
local Functions = {}; local Functions = {};
local ConstructorNumber = 1;
for line in fin:lines() do for line in fin:lines() do
-- Replace wiki-style markup: -- Replace wiki-style markup:
line = line:gsub("%[%[.-:.-:(.-)|(.-)%]%]", "{{%1|%2}}"); -- Replaces [[API:Plugin:Hook|LinkText]] line = line:gsub("%[%[.-:.-:(.-)|(.-)%]%]", "{{%1|%2}}"); -- Replaces [[API:Plugin:Hook|LinkText]]
line = line:gsub("%[%[.-:.-:(.-)%]%]", "{{%1|%1}}"); -- Replaces [[API:Plugin:Hook]]
line = line:gsub("%[%[.-:(.-)|(.-)%]%]", "{{%1|%2}}"); -- Replaces [[API:Class|LinkText]] line = line:gsub("%[%[.-:(.-)|(.-)%]%]", "{{%1|%2}}"); -- Replaces [[API:Class|LinkText]]
line = line:gsub("%[%[.-:(.-)%]%]", "{{%1|%1}}"); -- Replaces [[API:Class]]
line = line:gsub("%[%[(.-)|(.-)%]%]", "{{%1|%2}}"); -- Replaces [[Class|LinkText]]
line = line:gsub("%[%[(.-)%]%]", "{{%1|%1}}"); -- Replaces [[Class]]
if (line:find("======") ~= nil) then if (line:find("======") ~= nil) then
state = 1; -- The following is the class description state = 1; -- The following is the class description
ClassName = line:gsub("======", ""); ClassName = line:gsub("======", "");
@ -378,10 +385,10 @@ function ConvertWikiToDesc()
elseif (state == 1) then elseif (state == 1) then
-- Class description: -- Class description:
Desc = Desc .. AddNextTime .. line .. "\n";
if (line == "") then if (line == "") then
AddNextTime = "</p>\n<p>"; -- Replace empty lines with paragraph delimiters; add only when there's a followup text on next line AddNextTime = "</p>\n\t\t<p>"; -- Replace empty lines with paragraph delimiters; add only when there's a followup text on next line
else else
Desc = Desc .. AddNextTime .. line .. "\n";
AddNextTime = ""; AddNextTime = "";
end end
elseif (state == 2) then elseif (state == 2) then
@ -406,7 +413,8 @@ function ConvertWikiToDesc()
notes = notes:sub(1, notes:len() - 2); -- Remove the trailing " |" notes = notes:sub(1, notes:len() - 2); -- Remove the trailing " |"
local name = (Split[2] or ""); local name = (Split[2] or "");
if ((name == "( )") or (name == "()")) then if ((name == "( )") or (name == "()")) then
name = "constructor"; -- Special name is used for the constructor in the wiki name = "constructor" .. ConstructorNumber; -- Special name is used for the constructor in the wiki
ConstructorNumber = ConstructorNumber + 1;
end end
table.insert(Functions, {Name = name, Params = Split[3], Return = Split[4], Notes = notes}); table.insert(Functions, {Name = name, Params = Split[3], Return = Split[4], Notes = notes});
end end
@ -415,19 +423,22 @@ function ConvertWikiToDesc()
fin:close(); fin:close();
-- Write the info into the output file: -- Write the info into the output file:
fout:write(ClassName .. " =\n{\n\tDesc = [[" .. Desc .. "]]\n\tFunctions =\n\t{\n"); fout:write("\t\t" .. ClassName .. " =\n\t\t{\n\t\t\tDesc = [[" .. Desc .. "]],\n\t\t\tFunctions =\n\t\t\t{\n");
for i, func in ipairs(Functions) do for i, func in ipairs(Functions) do
fout:write("\t\t{ " .. func.Name .. " = { Params = \"" .. func.Params .. "\", Return =\"" .. fout:write(string.format("\t\t\t\t{ %s = { Params = %q, Return = %q, Notes = %q } },\n",
func.Return .. "\", Desc = \"" .. func.Notes .. "\" },\n" func.Name, func.Params, func.Return, func.Notes
); ));
end end
fout:write("\t},\n\tConstants =\n\t{\n"); fout:write("\t\t\t},\n\t\t\tConstants =\n\t\t\t{\n");
for i, cons in ipairs(Constants) do for i, cons in ipairs(Constants) do
fout:write("\t\t{ " .. cons.Name .. " = { Notes = \"" .. cons.Notes .. "\" },\n"); fout:write(string.format("\t\t\t\t{ %s = { Notes = %q } },\n",
cons.Name, cons.Notes
));
end end
fout:write("\t},\n},\n\n\n"); fout:write("\t\t\t},\n\t\t},\n\n");
end -- if fin ~= nil end -- if fin ~= nil
end -- for file end -- for file
fout:write("\t}\n}\n\n\n\n\n\n");
fout:close(); fout:close();
end end