Files
ClassicAPI/AddOns/!!!ClassicAPI/APIDocumentation/SystemsAPIMixin.lua
T
Brues 108a91a843 feat(api): describe the API in the code, browse it with /classicapi
docs/API.md is 18.7k lines and its anchors are signature slugs, so editing a
signature breaks the 281 internal and 88 README links into it. Blizzard
solved the same problem by shipping the API as data plus a browser addon,
and warcraft.wiki.gg renders those same tables. One set of descriptors can
feed all three.

Each registration now carries one next to it: typed arguments and returns,
nilability, defaults, and a sentence. Events, enumerations and returned table
shapes are described the same way. No Script_* body changed.

Game.h gains namespace Game::Doc (Field with Req/Opt/Vararg, FieldList,
Function, Method, Structure, Event) and a trailing descriptor argument on all
six Game::Lua::Register* plus Event::Custom::AutoReserve.

api/Documentation.cpp records every registration on the first pass of each
Lua state and seals it, so /reload re-registers but records nothing and the
environment comes from which pass saw the name. Export is lazy: nothing is
materialized until C_APIDocumentation.GetSystem asks for one system, because
eager export would build thousands of tables per reload for a slash command.
_classicapi_UndocumentedAPI lists what still has no descriptor.

AddOns/!!!ClassicAPI/APIDocumentation/ ports Blizzard_APIDocumentation's eight
files. Named /classicapi, not /api: the browser holds only what ClassicAPI
adds, so /api would have implied the whole 1.12 surface. Two deliberate
differences from the retail source, both noted in the file headers: a system
search also matches its namespace, since that is the name people type; and an
undocumented function says so, because an empty signature otherwise reads as
a real one.

LinkUtil gains the SetItemRef to LinkUtil.ProcessLink dispatch. That handler
registry was dead code; a new link type now registers a handler instead of
stacking another SetItemRef override. Also defines assertsafe there, which
was undefined and only mattered once the function went live.

Documented: the C_Spell and C_SpellBook surface, the spell globals, both
spellbook enumerations, the 13 UNIT_SPELLCAST_* events, GameTooltip as the
widget-method example and C_Glue as the glue and mixed-environment example.
66 of 692 function registrations. tools/New-ApiDocSkeletons.ps1 emits
paste-ready skeletons to make the rest of the sweep tractable.

Verified in game: the browser lists, searches, and prints detail; links
render and click through; right-click copies and shift-click dumps.
2026-09-12 23:20:46 -05:00

160 lines
4.2 KiB
Lua

-- Backport of Blizzard_APIDocumentation/SystemsAPIMixin.lua to vanilla 1.12 /
-- Lua 5.0.
--
-- Implementation differences from the retail source:
-- - Lua 5.0 has no length operator (#); sequence length comes from
-- table.getn(t), matching the rest of this addon.
-- - A search also matches a system's namespace. The namespace is the name
-- people type, and retail's version checks only the short name, so
-- "search C_Spell" found nothing while "search spell" found the system.
local tGetN = table.getn;
SystemsAPIMixin = CreateFromMixins(BaseAPIMixin);
function SystemsAPIMixin:GetType()
return "system";
end
function SystemsAPIMixin:GetLinkHexColor()
return "ff55dd";
end
function SystemsAPIMixin:GetNamespaceName()
return self.Namespace or "";
end
function SystemsAPIMixin:GetLoweredNamespaceName()
if not self.loweredNamespaceName then
self.loweredNamespaceName = self:GetNamespaceName():lower();
end
return self.loweredNamespaceName;
end
function SystemsAPIMixin:MatchesSearchString(searchString)
if self:GetLoweredName():match(searchString) then
return true;
end
local namespace = self:GetLoweredNamespaceName();
if namespace ~= "" and namespace:match(searchString) then
return true;
end
if self:MatchesAnyDocumentation(searchString) then
return true;
end
return false;
end
function SystemsAPIMixin:GetSingleOutputLine()
if self.Namespace then
return ("%s %s (%s)"):format(self:GetPrettyType(), self:GenerateAPILink(), self.Namespace);
end
return BaseAPIMixin.GetSingleOutputLine(self);
end
function SystemsAPIMixin:GetDetailedOutputLines()
local lines = {};
table.insert(lines, self:GetSingleOutputLine());
self:AddDocumentationTags(lines);
if self.Functions and tGetN(self.Functions) > 0 then
table.insert(lines, APIDocumentation:GetIndentString() .. "Functions");
for i, functionInfo in ipairs(self.Functions) do
table.insert(lines, APIDocumentation:GetIndentString(2) .. functionInfo:GetSingleOutputLine());
end
end
if self.Events and tGetN(self.Events) > 0 then
table.insert(lines, APIDocumentation:GetIndentString() .. "Events");
for i, eventInfo in ipairs(self.Events) do
table.insert(lines, APIDocumentation:GetIndentString(2) .. eventInfo:GetSingleOutputLine());
end
end
if self.Tables and tGetN(self.Tables) > 0 then
table.insert(lines, APIDocumentation:GetIndentString() .. "Tables");
for i, tableInfo in ipairs(self.Tables) do
table.insert(lines, APIDocumentation:GetIndentString(2) .. tableInfo:GetSingleOutputLine());
end
end
return lines;
end
function SystemsAPIMixin:MatchesName(name, parentName)
if BaseAPIMixin.MatchesName(self, name, parentName) then
return true;
end
return name == self:GetNamespaceName();
end
function SystemsAPIMixin:MatchesNameCaseInsenstive(name, parentName)
if BaseAPIMixin.MatchesNameCaseInsenstive(self, name, parentName) then
return true;
end
return name == self:GetLoweredNamespaceName();
end
function SystemsAPIMixin:FindAllAPIMatches(apiToSearchFor)
apiToSearchFor = apiToSearchFor:lower();
local matches = {
tables = {},
functions = {},
events = {},
};
APIDocumentationMixin:AddAllMatches(self.Tables, matches.tables, apiToSearchFor);
APIDocumentationMixin:AddAllMatches(self.Functions, matches.functions, apiToSearchFor);
APIDocumentationMixin:AddAllMatches(self.Events, matches.events, apiToSearchFor);
-- Only return something if we matched anything
for name, subTable in pairs(matches) do
if tGetN(subTable) > 0 then
return matches;
end
end
return nil;
end
local function AddAll(apiContainer, matchesContainer)
if apiContainer then
for i, apiInfo in ipairs(apiContainer) do
table.insert(matchesContainer, apiInfo);
end
end
end
function SystemsAPIMixin:ListAllAPI()
local allAPI = {
tables = {},
functions = {},
events = {},
};
AddAll(self.Tables, allAPI.tables);
AddAll(self.Functions, allAPI.functions);
AddAll(self.Events, allAPI.events);
return allAPI;
end
function SystemsAPIMixin:GetNumTables()
return self.Tables and tGetN(self.Tables) or 0;
end
function SystemsAPIMixin:GetNumFunctions()
return self.Functions and tGetN(self.Functions) or 0;
end
function SystemsAPIMixin:GetNumEvents()
return self.Events and tGetN(self.Events) or 0;
end