Skip to content

Foundry Tooltip

R edited this page Nov 4, 2026 · 2 revisions

Foundry.Tooltip

Part of the Foundry API reference.

New to WoW addons? Start here →

Foundry.Tooltip is a thin bridge over Blizzard's modern tooltip-hook system (TooltipDataProcessor, introduced in Retail 10.0.2). It encapsulates the AddTooltipPostCall registration pattern — choosing the correct Enum.TooltipDataType, applying an optional per-frame whitelist, and disabling the callback cleanly on teardown — so you call one factory and get a controller that owns the lifetime. It is not a tooltip-frame factory, not a retained content store, and not a merchant helper. You write the handler; Foundry owns the registration and the resulting controller.

API version: Foundry.Tooltip is API version 1. Assert it with F:RequireModule("Tooltip", 1) if your addon needs the module present at a minimum version. (This is the module's version; the library as a whole is F.API_VERSION.)


1. Mission

Every addon that adds lines to Blizzard tooltips needs the same boilerplate: call TooltipDataProcessor.AddTooltipPostCall with the right Enum.TooltipDataType, guard against being called for frames you do not own, and disable the callback cleanly when the feature is torn down — TooltipDataProcessor has no public removal API, so "cleanup" means checking a flag on every invocation rather than unregistering. Foundry.Tooltip encapsulates that pattern into a single factory, validated atomically, with a controller that carries the flag.

What the module does: typed post-call registration, optional per-frame whitelist, the duplicate-refusal registry, and clean in-place teardown via :Destroy(). Two convenience helpers — F.Tooltip.AddLine and F.Tooltip.AddSeparator — cover the patterns handlers repeat most often.

What the module does not do: create tooltip frames, retain tooltip-content state across show and hide cycles, hook all frame types via global hijacks, provide merchant money helpers, or fall back to legacy hooks such as OnTooltipSetItem on clients without TooltipDataProcessor (it ships on Retail 10.0.2+, Classic Era 1.15.x, and Pandaria Classic 5.5.x). Unregistering from TooltipDataProcessor is not possible; :Destroy() disables the registered callback in-place instead.


2. F.Tooltip:New(config) — the factory

local F = _G.Foundry_1_0

local itemController = F.Tooltip:New({
    type     = Enum.TooltipDataType.Item,    -- required: which tooltip type to hook
    handler  = function(tooltip, data)        -- required: fires per matching tooltip
        F.Tooltip.AddSeparator(tooltip)
        F.Tooltip.AddLine(tooltip, "My Addon info here")
    end,
    tooltips = { GameTooltip },              -- optional: restrict to specific frames
    name     = "MyAddon.ItemTooltip",        -- optional: duplicate-refusal key
})

:New returns a controller object. The controller owns the registered TooltipDataProcessor callback and the name key in Foundry's live registry. No event frame is created; Tooltip registers no WoW engine events.

Config fields

Field Type Required Meaning
type number yes An Enum.TooltipDataType value (e.g. Enum.TooltipDataType.Item). Determines which category of tooltip triggers your handler.
handler function yes Called as handler(tooltip, data) for each tooltip dispatch that passes the whitelist check. tooltip is the tooltip frame; data is the Blizzard data table for that type.
tooltips array of frames or nil no When supplied, the handler fires only when the incoming tooltip frame is one of the listed frames. nil fires for all tooltips of the registered type. An empty array means the handler never fires.
name non-empty string no The duplicate-refusal key stored in Foundry's module-level live registry. Defaults to tostring(type) when omitted. Freed when the controller is :Destroy()-ed.

Atomic validation

Validation is atomic. :New inspects every field before calling TooltipDataProcessor.AddTooltipPostCall. If any field is invalid, Foundry calls F:RaiseDevError(...) with a "Tooltip:New: ..." prefix and returns without registering anything. Prior registrations by other controllers are never touched.

Validation order:

  1. type — must be a number.
  2. handler — must be a function.
  3. tooltips — if supplied, must be a table; each indexed entry must be a table (a frame). Every element is validated before the call proceeds.
  4. name — if explicitly supplied, must be a non-empty string; omitting it defaults to tostring(type).
  5. Duplicate-key check — if the resolved name already belongs to a live controller, the call is refused.
  6. Feature detection — hasTooltipDataProcessor() is checked last, after all field validation passes. This ensures config errors surface as config errors rather than as client-incompatibility errors.

Duplicate-refusal registry

Foundry keeps a module-level liveKeys table mapping every active name string to true. A second :New with a key already in that table is refused and leaves existing registrations untouched. The key is freed only when :Destroy() is called on the controller that owns it. If you omit name, the key defaults to tostring(type) — meaning a second registration for the same Enum.TooltipDataType using the default key is also refused, even if the handlers differ.


3. Feature detection

Foundry detects TooltipDataProcessor by value inspection, not by version check:

local function hasTooltipDataProcessor()
    return type(_G.TooltipDataProcessor) == "table"
        and type(_G.TooltipDataProcessor.AddTooltipPostCall) == "function"
end

This check runs at :New time, not at file scope. Foundry does not probe the global at load; it waits until a registration is actually requested. This means the module loads cleanly on all clients, but :New fails loud on a client where TooltipDataProcessor is absent.

TooltipDataProcessor ships on Retail 10.0.2+, Classic Era 1.15.x, and Pandaria Classic 5.5.x. :New checks for TooltipDataProcessor and its AddTooltipPostCall function when you call it, not by client version. If either is missing, there is no fallback: Foundry does not attempt OnTooltipSetItem or any other legacy hook surface, and global tooltip hijacks are out of scope for Foundry. In a dev build, :New raises an error; in a release build it prints a message and returns nil. Foundry does not silently no-op.


4. Tooltip whitelist filter

When config.tooltips is a non-nil array, Foundry converts it to a hash set at :New time:

filter = {}
for i = 1, #tooltips do
    filter[tooltips[i]] = true
end

The resulting filter table is an O(1) lookup set. The registered callback checks filter[tooltip] on every invocation; a miss exits immediately without calling your handler.

Three cases:

  • tooltips is nil (the default): filter is nil; the handler fires for every tooltip of the registered type, regardless of which frame it is.
  • tooltips is a non-empty array: the handler fires only when the incoming tooltip frame is one of the listed frames.
  • tooltips is an empty array ({}): filter is a non-nil empty table; filter[tooltip] is always nil; the handler never fires. This is a legal but vacuous registration.

The filter table is released when :Destroy() is called.


5. Controller methods

Every method refuses on a destroyed controller with F:RaiseDevError("Tooltip:<Method> called on a destroyed controller").

:GetNativeHandles()

Returns the raw Blizzard objects this controller was built against. A fresh table is returned on every call; mutating the returned table does not corrupt controller state.

Key Value
tooltipDataProcessor _G.TooltipDataProcessor as read at call time.
type The Enum.TooltipDataType number passed to :New.

Note that tooltipDataProcessor is not a snapshot taken at :New time — it reads _G.TooltipDataProcessor at the moment :GetNativeHandles() is called. Called on a destroyed controller, the method refuses and returns nil.

:Destroy()

Marks the controller destroyed, frees the duplicate-refusal key from Foundry's liveKeys table, and releases internal references. Idempotent: a second :Destroy() is a silent no-op.

:Destroy() does not remove the registered callback from TooltipDataProcessor. TooltipDataProcessor.AddTooltipPostCall has no public removal counterpart. Instead, the registered wrapper holds the controller by upvalue and checks c._destroyed on every invocation; when the flag is set, the wrapper returns immediately. The callback slot remains in TooltipDataProcessor's dispatch list for the session, but it exits in one branch and adds no further cost after the flag check.

What :Destroy() guarantees:

  • The controller is marked destroyed; all further method calls are refused.
  • The name key is freed from liveKeys, so the same name can be used by a new :New call.
  • The _handler, _name, and _filter fields are nilled, releasing those references for garbage collection.

6. Line emitters

F.Tooltip.AddLine and F.Tooltip.AddSeparator are module-level functions, not controller methods. They operate on the tooltip argument delivered by TooltipDataProcessor; call them directly from your handler.

F.Tooltip.AddLine(tooltip, text, r, g, b)

Adds a line of text to the tooltip. r, g, b are optional; they default to 1, 1, 1 (white) when omitted. Equivalent to calling tooltip:AddLine(text, r, g, b) with explicit white defaults.

F.Tooltip.AddSeparator(tooltip)

Adds a blank separator line — a single space string — providing the standard inter-section visual gap. Equivalent to tooltip:AddLine(" ").

Both helpers operate directly on the tooltip frame passed by TooltipDataProcessor and have no return value.


7. Worked example

Registering a handler

Register from your addon's OnEnable or equivalent lifecycle point. Do not call :New at file scope — Enum.TooltipDataType must be resolved at runtime, not at parse time.

local F = _G.Foundry_1_0

local MyModule = {}

function MyModule:Initialize()
    self.tooltipController = F.Tooltip:New({
        type    = Enum.TooltipDataType.Item,
        handler = function(tooltip, data)
            -- Guard on the data you actually need before adding lines.
            if not data or not data.id then return end

            -- Add a visual separator before your content.
            F.Tooltip.AddSeparator(tooltip)

            -- Add a plain white line.
            F.Tooltip.AddLine(tooltip, "My Addon info for item " .. data.id)

            -- Add a coloured line (gold).
            F.Tooltip.AddLine(tooltip, "Tracked by My Addon", 1, 0.82, 0)
        end,
        tooltips = { GameTooltip, ItemRefTooltip },  -- restrict to two frames
        name     = "MyAddon.Item",
    })
end

Call MyModule:Initialize() from your lifecycle OnEnable (or equivalent). Do not call it at file scope — Enum.TooltipDataType and frame globals are not available at parse time.

Handling all tooltips of a type

Omit tooltips to fire for every tooltip that carries the registered type, regardless of which frame dispatched it:

local spellController = F.Tooltip:New({
    type    = Enum.TooltipDataType.Spell,
    handler = function(tooltip, data)
        F.Tooltip.AddSeparator(tooltip)
        F.Tooltip.AddLine(tooltip, "Spell ID: " .. (data.id or "?"), 0.5, 0.8, 1)
    end,
    -- no tooltips field — fires for all spell tooltips
    name = "MyAddon.Spell",
})

Teardown

At feature teardown or module disable, call :Destroy():

function MyModule:OnDisable()
    if self.tooltipController then
        self.tooltipController:Destroy()
        self.tooltipController = nil
    end
end

The callback continues to occupy a slot in TooltipDataProcessor's dispatch list, but it exits immediately on the _destroyed flag check and adds no meaningful cost.


8. What Foundry.Tooltip does not do

  • Global tooltip hijacks. Hooking all tooltip frame types (every GameTooltip:SetX call across the board) is out of scope for Foundry. Use the tooltips whitelist to restrict your handler to the specific frames you care about.
  • Merchant money tooltip helpers. Currency display, gold-amount formatting, and merchant-price lines are not provided by this module.
  • Retained tooltip-content state across show/hide. Foundry.Tooltip fires on each TooltipDataProcessor dispatch and has no memory of what was added on prior calls. If you need persistent state, maintain it yourself.
  • Taint-sensitive helpers. Foundry.Tooltip makes no attempt to wrap calls in pcall or to isolate taint. Your handler runs in the same execution context as TooltipDataProcessor's dispatch; taint rules apply as normal.
  • Legacy tooltip hook fallback. If TooltipDataProcessor is unavailable on a client, :New fails loud; there is no OnTooltipSetItem fallback.
  • Unregistering from TooltipDataProcessor. TooltipDataProcessor.AddTooltipPostCall has no public removal API. :Destroy() disables the registered callback in-place via a flag check; it does not remove the callback slot from the dispatch list.

9. Escape hatch: GetNativeHandles()

When you need a Blizzard object that Foundry.Tooltip does not expose through its own API, drop to the native surface without removing the controller:

local handles = itemController:GetNativeHandles()
-- handles.tooltipDataProcessor  == _G.TooltipDataProcessor
-- handles.type                  == Enum.TooltipDataType.Item (the number you passed)

The returned table is a fresh table on every call. Mutating it does not affect the controller. tooltipDataProcessor is a live reference to the global — calling methods on it reaches Blizzard's live dispatch surface directly.

Common reasons to use this:

  • You need to pass the type value to another API that expects a raw Enum.TooltipDataType number.
  • You want to inspect tooltipDataProcessor directly during debugging — for example to verify the global is still the object you registered against.
  • A Blizzard API you are calling expects the processor object itself rather than going through a Foundry wrapper.

If you find yourself reaching into native handles to work around a missing controller method, that is a signal the missing method belongs in Foundry.Tooltip. File a feature request instead of building a permanent workaround on top of the escape hatch.

Called on a destroyed controller, :GetNativeHandles refuses like every other post-Destroy call and returns nil.

Clone this wiki locally