From 24e70d534b8cf6afac421ea616824c5731a8c0e5 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 13 Sep 2013 10:51:01 +0200 Subject: [PATCH] APIDump: Added descendants specified through inheritance. --- MCServer/Plugins/APIDump/main.lua | 86 +++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 27 deletions(-) diff --git a/MCServer/Plugins/APIDump/main.lua b/MCServer/Plugins/APIDump/main.lua index 3ec6a1ccd..79559eab4 100644 --- a/MCServer/Plugins/APIDump/main.lua +++ b/MCServer/Plugins/APIDump/main.lua @@ -87,6 +87,7 @@ function CreateAPITables() }, Constants = { } + Descendants = {}, -- Will be filled by ReadDescriptions(), array of class APIs (references to other member in the tree) }}, { Name = "cBlockArea", @@ -113,25 +114,27 @@ function CreateAPITables() }; --]] - local Globals = {Functions = {}, Constants = {}}; + local Globals = {Functions = {}, Constants = {}, Descendants = {}}; local API = {}; local function Add(a_APIContainer, a_ClassName, a_ClassObj) if (type(a_ClassObj) == "function") then table.insert(a_APIContainer.Functions, {Name = a_ClassName}); - elseif (type(a_ClassObj) == "number") then + elseif ( + (type(a_ClassObj) == "number") or + (type(a_ClassObj) == "string") + ) then table.insert(a_APIContainer.Constants, {Name = a_ClassName, Value = a_ClassObj}); end end local function SortClass(a_ClassAPI) - -- Sort the function list and constant lists: - table.sort(a_ClassAPI.Functions, + table.sort(a_ClassAPI.Functions, -- Sort function list function(f1, f2) return (f1.Name < f2.Name); end ); - table.sort(a_ClassAPI.Constants, + table.sort(a_ClassAPI.Constants, -- Sort constant list function(c1, c2) return (c1.Name < c2.Name); end @@ -139,7 +142,7 @@ function CreateAPITables() end; local function ParseClass(a_ClassName, a_ClassObj) - local res = {Name = a_ClassName, Functions = {}, Constants = {}}; + local res = {Name = a_ClassName, Functions = {}, Constants = {}, Descendants = {}}; for i, v in pairs(a_ClassObj) do Add(res, i, v); end @@ -223,7 +226,16 @@ function ReadDescriptions(a_API) local APIDesc = g_APIDesc.Classes[cls.Name]; if (APIDesc ~= nil) then cls.Desc = APIDesc.Desc; - cls.Inherits = APIDesc.Inherits; + + -- Process inheritance: + if (APIDesc.Inherits ~= nil) then + for j, icls in ipairs(a_API) do + if (icls.Name == APIDesc.Inherits) then + table.insert(icls.Descendants, cls); + cls.Inherits = icls; + end + end + end if (APIDesc.Functions ~= nil) then -- Assign function descriptions: @@ -261,7 +273,16 @@ function ReadDescriptions(a_API) end -- if (APIDesc.Constants ~= nil) end - end -- for i, class + end -- for i, cls + + -- Sort the descendants lists: + for i, cls in ipairs(a_API) do + table.sort(cls.Descendants, + function(c1, c2) + return (c1.Name < c2.Name); + end + ); + end -- for i, cls end @@ -280,19 +301,6 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI) return a_String; end - -- Returns the ClassAPI for the inherited class, or nil if not found - local function FindInheritedClassAPI(a_AllAPI, a_InheritedClassName) - if (a_InheritedClassName == nil) then - return nil; - end - for i, cls in ipairs(a_AllAPI) do - if (cls.Name == a_InheritedClassName) then - return cls; - end - end - return nil; - end - -- Writes a table containing all functions in the specified list, with an optional "inherited from" header when a_InheritedName is valid local function WriteFunctions(a_Functions, a_InheritedName) if (#a_Functions == 0) then @@ -310,13 +318,26 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI) end cf:write("\n"); end + + local function WriteDescendants(a_Descendants) + if (#a_Descendants == 0) then + return; + end + cf:write("\n"); + end -- Build an array of inherited classes chain: local InheritanceChain = {}; - local CurrInheritance = FindInheritedClassAPI(a_AllAPI, a_ClassAPI.Inherits); + local CurrInheritance = a_ClassAPI.Inherits; while (CurrInheritance ~= nil) do table.insert(InheritanceChain, CurrInheritance); - CurrInheritance = FindInheritedClassAPI(a_AllAPI, CurrInheritance.Inherits); + CurrInheritance = CurrInheritance.Inherits; end cf:write([[MCServer API - ]] .. a_ClassAPI.Name .. [[ @@ -326,8 +347,10 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)