Files
ClassicAPI/AddOns/!!!ClassicAPI/APIDocumentation/BaseAPIMixin.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

116 lines
2.8 KiB
Lua

-- Backport of Blizzard_APIDocumentation/BaseAPIMixin.lua to vanilla 1.12 /
-- Lua 5.0.
--
-- Implementation differences from the retail source: none. Every construct
-- here (method calls on string literals, string.format's %s, table.insert,
-- ipairs, CreateFromMixins) exists on this client.
BaseAPIMixin = {};
function BaseAPIMixin:GetType()
return assert(false);
end
function BaseAPIMixin:GetPrettyType()
return self:GetType();
end
function BaseAPIMixin:GetLinkHexColor()
return "ffffff";
end
function BaseAPIMixin:GetName()
return self.Name;
end
function BaseAPIMixin:GetFullName()
return self:GetName();
end
function BaseAPIMixin:GetParentName()
return "";
end
function BaseAPIMixin:GetLoweredParentName()
if not self.loweredParentName then
self.loweredParentName = self:GetParentName():lower();
end
return self.loweredParentName;
end
function BaseAPIMixin:GetLoweredName()
if not self.loweredName then
self.loweredName = self:GetName():lower();
end
return self.loweredName;
end
function BaseAPIMixin:GetClipboardString()
return self:GetFullName();
end
function BaseAPIMixin:GenerateAPILink()
return ("|cff%s|Hapi:%s:%s:%s|h%s|h|r"):format(self:GetLinkHexColor(), self:GetType(), self:GetName(), self:GetParentName(), self:GetFullName());
end
function BaseAPIMixin:GetSingleOutputLine()
return ("%s %s"):format(self:GetPrettyType(), self:GenerateAPILink());
end
function BaseAPIMixin:GetDetailedOutputLines()
return { self:GetSingleOutputLine() };
end
function BaseAPIMixin:MatchesSearchString(searchString)
return false;
end
function BaseAPIMixin:MatchesName(name, parentName)
if name == self:GetName() then
return not parentName or parentName == self:GetParentName();
end
return false;
end
function BaseAPIMixin:MatchesNameCaseInsenstive(name, parentName)
if name == self:GetLoweredName() then
return not parentName or parentName == self:GetLoweredParentName();
end
return false;
end
function BaseAPIMixin:MatchesAnyAPI(apiTable, searchString)
if apiTable then
for i, apiInfo in ipairs(apiTable) do
if apiInfo:MatchesSearchString(searchString) then
return true;
end
end
end
return false;
end
function BaseAPIMixin:MatchesAnyDocumentation(searchString)
if self.Documentation then
for i, documentation in ipairs(self.Documentation) do
if documentation:lower():match(searchString) then
return true;
end
end
end
end
function BaseAPIMixin:AddDocumentationTags(lines)
if self.Documentation then
for i, documentation in ipairs(self.Documentation) do
table.insert(lines, APIDocumentation:GetIndentString() .. documentation);
end
end
end
function BaseAPIMixin:AddSystemTag(lines)
if self.System then
table.insert(lines, APIDocumentation:GetIndentString() .. ("Part of the %s system"):format(self.System:GenerateAPILink()));
end
end