From 3109762e34878af910bc046584a2fca243949791 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 12 Sep 2013 20:38:30 +0200 Subject: APIDump: Imported the descriptions from the wiki. --- MCServer/Plugins/APIDump/main.lua | 150 -------------------------------------- 1 file changed, 150 deletions(-) (limited to 'MCServer/Plugins/APIDump/main.lua') diff --git a/MCServer/Plugins/APIDump/main.lua b/MCServer/Plugins/APIDump/main.lua index 5d0070be3..3988857c9 100644 --- a/MCServer/Plugins/APIDump/main.lua +++ b/MCServer/Plugins/APIDump/main.lua @@ -26,9 +26,6 @@ function Initialize(Plugin) -- dump all available API functions and objects: -- DumpAPITxt(); - -- DEBUG: Convert the wiki dump into APIDesc - ConvertWikiToDesc(); - -- Dump all available API object in HTML format into a subfolder: DumpAPIHtml(); @@ -339,150 +336,3 @@ end --- This function converts the wiki dump, as provided by FakeTruth, into the APIDesc format. --- Dump available in forum: http://forum.mc-server.org/showthread.php?tid=1214&pid=9892#pid9892 --- The dump is expected unpacked as "wikipages/api/*.txt", in the executable folder --- Only Windows-style paths are supported for now, since this is a one-time action -function ConvertWikiToDesc() - 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 - -- Read file - local fin = io.open("wikipages\\api\\" .. filename, "r"); - local ClassName = filename:match("[^\.]*"); - local AddNextTime = ""; - if (fin ~= nil) then - -- Read and parse the info from the file - local state = 0; - local Desc = ""; - local Constants = {}; - local Functions = {}; - local ConstructorNumber = 1; - for line in fin:lines() do - -- Replace wiki-style markup: - 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|%1}}"); -- Replaces [[API:Class]] - line = line:gsub("%[%[(.-)|(.-)%]%]", "{{%1|%2}}"); -- Replaces [[Class|LinkText]] - line = line:gsub("%[%[(.-)%]%]", "{{%1|%1}}"); -- Replaces [[Class]] - - if (line:find("======") ~= nil) then - state = 1; -- The following is the class description - ClassName = line:gsub("======", ""); - ClassName = ClassName:match("%w+"); - if (ClassName == nil) then - -- Reset to default - ClassName = filename:match("[^\.]*"); - end - AddNextTime = ""; - elseif (line:find("===== Constants") ~= nil) then - state = 2; -- The following is the constants description - elseif (line:find("===== Functions") ~= nil) then - state = 3; -- The following is the functions description - elseif (line:find("===== Class [Dd]efinition ==") ~= nil) then - state = 4; -- The following contains both functions' and constants' descriptions - elseif (line:find("=====") ~= nil) then - state = 5; -- The following is an unknown text, skip it entirely - - elseif (state == 1) then - -- Class description: - if (line == "") then - AddNextTime = "

\n\t\t

"; -- Replace empty lines with paragraph delimiters; add only when there's a followup text on next line - else - -- Replace wiki-style bullets with

  • tag: - if (line:find("^ +%*")) then - line = line:gsub("^ +%* *", "
  • ") .. "
  • "; - end - Desc = Desc .. AddNextTime .. line .. "\n"; - AddNextTime = ""; - end - - elseif (state == 2) then - -- Constants: - line = line:gsub("| ", "\n"); - local Split = StringSplitAndTrim(line, "\n"); - if (#Split >= 3) then - -- Split[1] is always "", because the line starts with a "|" - local notes = Split[3] or ""; - notes = notes:sub(1, notes:len() - 2); -- Remove the trailing " |" - local name = (Split[2] or ""); - name = name:match("%a+"); - if ((name ~= "") and (name ~= nil)) then - table.insert(Constants, {Name = name, Notes = notes}); - end - end - - elseif (state == 3) then - -- Functions: - line = string.gsub(line, "| ", "\n"); - local Split = StringSplitAndTrim(line, "\n"); - if (#Split >= 5) then - -- Split[1] is always "", because the line starts with a "|" - local notes = Split[5] or ""; - notes = notes:sub(1, notes:len() - 2); -- Remove the trailing " |" - local name = (Split[2] or ""); - if ((name == "( )") or (name == "()")) then - name = "constructor" .. ConstructorNumber; -- Special name is used for the constructor in the wiki - ConstructorNumber = ConstructorNumber + 1; - end - name = name:match("%a+"); - if ((name ~= "") and (name ~= nil)) then - table.insert(Functions, {Name = name, Params = Split[3], Return = Split[4], Notes = notes}); - end - end - - elseif (state == 4) then - -- Constants and functions interspersed: - line = line:gsub("| ", "\n"); - local Split = StringSplitAndTrim(line, "\n"); - if (#Split >= 5) then - -- Split[1] is always "", because the line starts with a "|" - local notes = Split[5] or ""; - notes = notes:sub(1, notes:len() - 2); -- Remove the trailing " |" - local name = (Split[2] or ""); - if ((name == "( )") or (name == "()")) then - name = "constructor" .. ConstructorNumber; -- Special name is used for the constructor in the wiki - ConstructorNumber = ConstructorNumber + 1; - end - name = name:match("%a+"); - if ((name ~= "") and (name ~= nil)) then - table.insert(Functions, {Name = name, Params = Split[3], Return = Split[4], Notes = notes}); - end - elseif (#Split >= 3) then - -- Split[1] is always "", because the line starts with a "|" - local notes = Split[3] or ""; - notes = notes:sub(1, notes:len() - 2); -- Remove the trailing " |" - local name = (Split[2] or ""); - name = name:match("%a+"); - if ((name ~= "") and (name ~= nil)) then - table.insert(Constants, {Name = name, Notes = notes}); - end - end - end - end -- for line - fin:close(); - - -- Write the info into the output file: - 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 - fout:write(string.format("\t\t\t\t%s = { Params = %q, Return = %q, Notes = %q },\n", - func.Name, func.Params, func.Return, func.Notes - )); - end - fout:write("\t\t\t},\n\t\t\tConstants =\n\t\t\t{\n"); - for i, cons in ipairs(Constants) do - fout:write(string.format("\t\t\t\t%s = { Notes = %q },\n", - cons.Name, cons.Notes - )); - end - fout:write("\t\t\t},\n\t\t},\n\n"); - end -- if fin ~= nil - end -- for file - fout:write("\t}\n}\n\n\n\n\n\n"); - fout:close(); -end - - - - -- cgit v1.2.3