From 07ba48840da5447e12d8c54a20c0f049a3ec67a7 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 18 Oct 2013 21:29:38 +0200 Subject: APIDump: Added support for member variables. --- MCServer/Plugins/APIDump/APIDesc.lua | 9 ++++-- MCServer/Plugins/APIDump/main.lua | 54 ++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) (limited to 'MCServer/Plugins/APIDump') diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 4961c9baf..0a1e91a54 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -31,6 +31,11 @@ g_APIDesc = ConstantName = { Notes = "Notes about the constant" }, } , + Variables = + { + VariableName = { Type = "string", Notes = "Notes about the variable" }, + } , + AdditionalInfo = -- Paragraphs to be exported after the function definitions table { { @@ -610,8 +615,8 @@ World:ForEachChestInChunk(Player:GetChunkX(), Player:GetChunkZ(), }, Variables = { - p1 = { Notes = "{{Vector3i}} of one corner. Usually the lesser of the two coords in each set" }, - p2 = { Notes = "{{Vector3i}} of the other corner. Usually the larger of the two coords in each set" }, + p1 = { Type = "{{Vector3i}}", Notes = "The first corner. Usually the lesser of the two coords in each set" }, + p2 = { Type = "{{Vector3i}}", Notes = "The second corner. Usually the larger of the two coords in each set" }, }, }, diff --git a/MCServer/Plugins/APIDump/main.lua b/MCServer/Plugins/APIDump/main.lua index 6d85a1281..93f3e7258 100644 --- a/MCServer/Plugins/APIDump/main.lua +++ b/MCServer/Plugins/APIDump/main.lua @@ -459,10 +459,21 @@ function ReadDescriptions(a_API) end end -- for j, cons end -- if (APIDesc.Constants ~= nil) - else + + -- Process member variables: + local vars = {}; + for name, desc in pairs(APIDesc.Variables or {}) do + desc.Name = name; + table.insert(vars, desc); + end + cls.Variables = vars; + + else -- if (APIDesc ~= nil) + -- Class is not documented at all, add all its members to Undocumented lists: cls.UndocumentedFunctions = {}; cls.UndocumentedConstants = {}; + cls.Variables = {}; for j, func in ipairs(cls.Functions) do local FnName = func.DocID or func.Name; if not(IsFunctionIgnored(cls.Name .. "." .. FnName)) then @@ -505,6 +516,13 @@ function ReadDescriptions(a_API) return (c1.Name < c2.Name); end ); + + -- Sort the member variables: + table.sort(cls.Variables, + function(v1, v2) + return (v1.Name < v2.Name); + end + ); end -- for i, cls -- Sort the descendants lists: @@ -618,7 +636,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI) cf:write(" \n " .. func.Name .. "\n"); cf:write(" " .. LinkifyString(func.Params or "", (a_InheritedName or a_ClassAPI.Name)).. "\n"); cf:write(" " .. LinkifyString(func.Return or "", (a_InheritedName or a_ClassAPI.Name)).. "\n"); - cf:write(" " .. LinkifyString(func.Notes or "", (a_InheritedName or a_ClassAPI.Name)) .. "\n \n"); + cf:write(" " .. LinkifyString(func.Notes or "(undocumented)", (a_InheritedName or a_ClassAPI.Name)) .. "\n \n"); end cf:write(" \n\n"); end @@ -641,6 +659,24 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI) cf:write(" \n\n"); end + local function WriteVariables(a_Variables, a_InheritedName) + if (#a_Variables == 0) then + return; + end + + if (a_InheritedName ~= nil) then + cf:write("

Member variables inherited from " .. a_InheritedName .. "

\n"); + end + + cf:write(" \n \n \n \n \n \n"); + for i, var in ipairs(a_Variables) do + cf:write(" \n \n"); + cf:write(" \n"); + cf:write(" \n \n"); + end + cf:write("
NameTypeNotes
" .. var.Name .. "" .. LinkifyString(var.Type or "(undocumented)", a_InheritedName or a_ClassAPI.Name) .. "" .. LinkifyString(var.Notes or "", a_InheritedName or a_ClassAPI.Name) .. "
\n\n"); + end + local function WriteDescendants(a_Descendants) if (#a_Descendants == 0) then return; @@ -688,10 +724,12 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI) local HasConstants = (#a_ClassAPI.Constants > 0); local HasFunctions = (#a_ClassAPI.Functions > 0); + local HasVariables = (#a_ClassAPI.Variables > 0); if (a_ClassAPI.Inherits ~= nil) then for idx, cls in ipairs(a_ClassAPI.Inherits) do HasConstants = HasConstants or (#cls.Constants > 0); HasFunctions = HasFunctions or (#cls.Functions > 0); + HasVariables = HasVariables or (#cls.Variables > 0); end end @@ -702,6 +740,9 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI) if (HasConstants) then cf:write("
  • Constants
  • \n"); end + if (HasVariables) then + cf:write("
  • Member variables
  • \n"); + end if (HasFunctions) then cf:write("
  • Functions
  • \n"); end @@ -746,6 +787,15 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI) end; end; + -- Write the member variables: + if (HasVariables) then + cf:write("

    Member variables

    \n"); + WriteVariables(a_ClassAPI.Variables, nil); + for i, cls in ipairs(InheritanceChain) do + WriteVariables(cls.Variables, cls.Name); + end; + end + -- Write the functions, including the inherited ones: if (HasFunctions) then cf:write("

    Functions

    \n"); -- cgit v1.2.3