Repository navigation
Ace to Foundry Migration
Part of the Foundry API reference.
Foundry is not an Ace3 clone. It replaces the common addon plumbing authors usually reach for Ace3 to solve: slash commands, WoW events, addon lifecycle, SavedVariables, modern scrolling lists, options-panel registration, context menus, and tooltip hooks.
The goal is a smaller native-first layer, not perfect API compatibility. Migrate one surface at a time, keep your addon working between steps, and migrate saved data last.
Make Foundry available before your addon code. For packaging details, see Packaging Foundry.
In Lua, bind the runtime:
local ADDON_NAME = ...
local F = _G.Foundry_1_0
if not F then
error("MyAddon requires Foundry-1.0. Please install or enable it.")
endWhen a module is required, assert the module and API version up front:
local Commands = F:RequireModule("Commands", 1)Recommended migration order:
- Commands
- Events
- Lifecycle
- Lists
- Menus and tooltips
- Options panel (Settings)
- DB
DB is last because SavedVariables mistakes are the easiest way to hurt users.
Foundry.Commands replaces RegisterChatCommand, slash aliases, subcommand
dispatch, generated help, guard checks, and teardown.
It does not replace AceConfig command integration, option-table parsing, or typed argument parsing.
Full reference: Foundry.Commands
local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceConsole-3.0")
function MyAddon:OnInitialize()
self:RegisterChatCommand("myaddon", "SlashCommand")
self:RegisterChatCommand("ma", "SlashCommand")
end
function MyAddon:SlashCommand(input)
input = input or ""
local cmd, rest = input:match("^(%S*)%s*(.-)$")
cmd = (cmd or ""):lower()
if cmd == "" then
self:OpenOptions()
elseif cmd == "debug" then
self.db.profile.debug = not self.db.profile.debug
self:Print("Debug " .. tostring(self.db.profile.debug))
elseif cmd == "scan" then
self:Scan(rest)
else
self:Print("Unknown command.")
end
endlocal Commands = F:RequireModule("Commands", 1)
MyAddon.commands = Commands:New({
name = "MyAddon",
slashes = { "/myaddon", "/ma" },
description = "MyAddon commands.",
defaultHandler = function()
MyAddon:OpenOptions()
end,
unknownMessage = function(input)
return "Unknown command: " .. input .. ". Type /myaddon help."
end,
})
MyAddon.commands:Register({
name = "debug",
help = "Toggle debug mode.",
handler = function()
MyAddon.db.profile.debug = not MyAddon.db.profile.debug
print("Debug " .. tostring(MyAddon.db.profile.debug))
end,
})
MyAddon.commands:Register({
name = "scan",
args = "[filter]",
help = "Run a scan.",
handler = function(rest)
MyAddon:Scan(rest)
end,
})-
helpis reserved for generated help. - Subcommand handlers receive the remaining argument string, not
self, input. - Foundry refuses duplicate slash names instead of overwriting them.
- Multi-word commands are registered as flat names, for example
name = "debug vertical". - AceConsole's
self:Printprefixes each line with your addon name; a bareprintdoes not. If you want the prefix back, pass aprinterfunction toCommands:Newand it is used for all controller output (help, unknown-command messages, guard denials). - If your AceConsole command opened AceConfig options, the handler can keep
doing that, or call
:Open()on a Foundry.Settings controller once you migrate the options panel (see the Settings section below).
Foundry.Events replaces AceEvent's WoW event registration surface:
RegisterEvent, RegisterUnitEvent, unregistering, and one-shot event
handlers.
It does not replace AceEvent messages, AceComm, CallbackHandler, or your addon's internal pub/sub bus.
Full reference: Foundry.Events
local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceEvent-3.0")
function MyAddon:OnEnable()
self:RegisterEvent("PLAYER_ENTERING_WORLD", "OnEnteringWorld")
self:RegisterEvent("BAG_UPDATE_DELAYED")
end
function MyAddon:OnEnteringWorld(event, isInitialLogin, isReload)
self:Refresh()
end
function MyAddon:BAG_UPDATE_DELAYED(event)
self:RefreshBags()
endlocal Events = F:RequireModule("Events", 1)
MyAddon.events = Events:New("MyAddon")
MyAddon.events:Register("PLAYER_ENTERING_WORLD", function(event, isInitialLogin, isReload)
MyAddon:Refresh()
end)
MyAddon.events:Register("BAG_UPDATE_DELAYED", function(event)
MyAddon:RefreshBags()
end)- Handlers receive
event, ...; Foundry drops the native frame argument. - Each controller allows one handler per event. To replace a handler, unregister it first.
- Use
RegisterUnitfor unit-filtered events. - Use
RegisterOncefor one-shot events. - If two feature modules both need the same event, prefer one Events controller per module, or fan out yourself from a single registered handler.
- If your addon uses
RegisterMessage/SendMessage, keep that system or migrate it separately; Foundry.Events is only for WoW frame events.
If your addon uses AceBucket's RegisterBucketEvent to coalesce bursty events,
the same controller covers it:
-- Before (AceBucket-3.0)
self:RegisterBucketEvent("BAG_UPDATE", 0.5, "RefreshBags")
-- After
MyAddon.events:RegisterBucket({
events = "BAG_UPDATE",
interval = 0.5,
handler = function() MyAddon:RefreshBags() end,
})events also accepts an array of event names sharing one window. The returned
handle has :Cancel() and :IsPending(). Bucket support requires Events API
version 2: assert it with F:RequireModule("Events", 2). Full details:
Foundry.Events §5.
Foundry.Lifecycle replaces the common startup handling around ADDON_LOADED,
PLAYER_LOGIN, and PLAYER_LOGOUT.
It does not replace AceAddon modules, runtime enable/disable state, dependency
ordering, or OnDisable.
Full reference: Foundry.Lifecycle
local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceEvent-3.0")
function MyAddon:OnInitialize()
self:InitDB()
end
function MyAddon:OnEnable()
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:BuildUI()
end
function MyAddon:OnDisable()
self:UnregisterAllEvents()
endlocal Lifecycle = F:RequireModule("Lifecycle", 1)
MyAddon = MyAddon or {}
MyAddon.lifecycle = Lifecycle:New(MyAddon, ADDON_NAME)
MyAddon.lifecycle:OnAddonLoaded(function(owner)
owner:InitDB()
end)
MyAddon.lifecycle:OnLogin(function(owner)
owner:StartRuntime()
owner:BuildUI()
end)
MyAddon.lifecycle:OnLogout(function(owner)
owner:FlushRuntimeState()
end)
-- There is no OnDisable equivalent; teardown like this is called from your
-- own feature code (a settings toggle, a slash command) when you turn a
-- feature off.
function MyAddon:StopRuntime()
if self.events then
self.events:Destroy()
self.events = nil
end
end- Lifecycle adopts your table; it does not create or decorate your addon object.
- Hooks are one-shot.
-
OnAddonLoadedis the right place to initialize SavedVariables-backed state. -
OnLogincatches up ifPLAYER_LOGINalready fired. -
Destroyunsubscribes from future phases; it does not fire logout. - There is no
OnDisablereplacement. Feature enable/disable behavior should live in your own module code, usually with Events controllers you can destroy or unregister.
Foundry.List replaces the boilerplate for a simple modern ScrollBox linear list.
It does not replace grids, trees, column tables, secure lists, FauxScrollFrame fallbacks, or custom scrolling architectures.
Full reference: Foundry.List
local rows = {}
local function Update()
FauxScrollFrame_Update(MyScrollFrame, #rows, 10, 24)
for i = 1, 10 do
local row = _G["MyAddonRow" .. i]
local index = i + FauxScrollFrame_GetOffset(MyScrollFrame)
local data = rows[index]
if data then
row.Text:SetText(data.name)
row:Show()
else
row:Hide()
end
end
endlocal List = F:RequireModule("List", 1)
MyAddon.list = List:New({
name = "MyAddonList",
parent = MyAddonListContainer,
template = "MyAddonListRowTemplate",
extent = 24,
spacing = 2,
initializer = function(frame, elementData)
frame.Text:SetText(elementData.name)
frame.Icon:SetTexture(elementData.icon)
end,
resetter = function(frame)
frame.Text:SetText("")
frame.Icon:SetTexture(nil)
end,
managedScrollBarVisibility = true,
})
MyAddon.list:SetData({
{ name = "First row", icon = 134400 },
{ name = "Second row", icon = 134401 },
})- Rows must be an array of tables.
- Do not call
SetDatafrom inside the initializer. - Your initializer must fully repaint a recycled row.
- Use
ForEachFramefor in-place visual updates, such as repainting selection. - Use
GetNativeHandles()when you need to re-anchor the ScrollBox or scrollbar for a custom layout. - If you still support a client without modern ScrollBox, keep a legacy path and gate List adoption.
Foundry.Menu replaces the entry-point plumbing for context menus and dropdowns
on Blizzard's modern menu system (MenuUtil, Retail 11.0+ and all current
Classic flavors).
It does not provide UIDropDownMenu or EasyMenu compatibility shims: you write
your menu content against Blizzard's modern rootDescription API, which is
usually shorter than the old info-table code it replaces.
Full reference: Foundry.Menu
local menu = {
{ text = "MyAddon", isTitle = true },
{ text = "Show Pins", checked = ShowPins, func = TogglePins },
{ text = "Open Settings", func = OpenSettings },
}
EasyMenu(menu, menuFrame, "cursor", 0, 0, "MENU")local Menu = F:RequireModule("Menu", 1)
MyAddon.menu = Menu:New({
name = "MyAddon.ContextMenu",
builder = function(owner, rootDescription)
rootDescription:CreateTitle("MyAddon")
rootDescription:CreateCheckbox("Show Pins", IsShowingPins, TogglePins)
rootDescription:CreateButton("Open Settings", OpenSettings)
end,
})
-- At the callsite (e.g. a right-click handler):
MyAddon.menu:CreateContextMenu(ownerFrame)- The
builderruns every time the menu opens; read live state inside it. - Create controllers once and store them; a
Menu:Newinside a click handler creates (and leaks) a new controller per click. -
rootDescriptionis Blizzard's raw object:CreateTitle,CreateButton,CreateCheckbox,CreateRadio,CreateDividerare Blizzard methods, not Foundry ones. - For persistent dropdown buttons, use
:SetupDropdown(dropdownButton)instead of:CreateContextMenu.
Foundry.Tooltip replaces hand-rolled TooltipDataProcessor.AddTooltipPostCall
registration, the modern successor to the removed OnTooltipSetItem script
hooks.
Full reference: Foundry.Tooltip
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, function(tooltip, data)
if tooltip ~= GameTooltip then return end
if not MyAddon.enabled then return end
tooltip:AddLine("MyAddon info here")
end)local Tooltip = F:RequireModule("Tooltip", 1)
MyAddon.tooltip = Tooltip:New({
type = Enum.TooltipDataType.Item,
tooltips = { GameTooltip },
name = "MyAddon.ItemTooltip",
handler = function(tooltip, data)
F.Tooltip.AddSeparator(tooltip)
F.Tooltip.AddLine(tooltip, "MyAddon info here")
end,
})- Blizzard provides no way to unregister a TooltipDataProcessor callback;
:Destroy()disables the handler in place instead. -
TooltipDataProcessorships on Retail 10.0.2+, Classic Era 1.15.x, and Pandaria Classic 5.5.x. On a client without it,:Newraises an error in dev builds and prints a message and returns nil in release builds, so check the result. - The optional
tooltipswhitelist replaces theif tooltip ~= GameTooltipguard boilerplate.
Read this section carefully: Settings covers less of AceConfig than the other modules cover of their Ace3 counterparts.
Foundry.Settings replaces the options-panel registration idiom: the
Settings.RegisterCanvasLayoutCategory + RegisterAddOnCategory pair and
category bookkeeping. If your options already open in your own window, it can
also register a launcher entry, a single button in the Settings panel that
opens that window (see Foundry.Settings §8).
It is not a widget factory and not an options framework. AceConfig renders a declarative options table into checkboxes, sliders, and dropdowns for you; with Foundry you build and wire that panel frame yourself, using Blizzard templates. If your options UI is a large AceConfig table and you do not want to hand-build a panel, keeping AceConfig/AceConfigDialog is a legitimate long-term choice: registration and rendering are separable concerns.
Foundry.DB also has no profile-management UI (no AceDBOptions equivalent); see the DB section below.
Full reference: Foundry.Settings
LibStub("AceConfig-3.0"):RegisterOptionsTable("MyAddon", options)
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MyAddon", "My Addon")-- If another addon loaded an older Foundry first, that copy serves every addon.
-- RequireModule errors when the loaded copy is older than the version you ask for.
local Settings = F:RequireModule("Settings", 2)
local panel = CreateFrame("Frame", "MyAddonSettingsPanel")
panel.name = "My Addon"
-- Build your controls on `panel` with Blizzard templates; wire them to your
-- saved settings yourself.
MyAddon.settings = Settings:New({
title = "My Addon",
frame = panel,
})
-- Open it from a slash command or minimap button:
MyAddon.settings:Open()-
titlelabels the Settings category. Foundry does not readpanel.name. - Subcategories: pass the parent controller as
parent. -
OnCommit/OnRefresh/OnDefaultcallbacks stay on your panel frame, where Blizzard designed them to live.
Migrate DB last. Back up real SavedVariables before testing a DB migration.
⚠ Keep your SavedVariables name exactly as it is. The
svvalue you pass toDB:Newand the## SavedVariables:line in your TOC must stay the same global your addon shipped under AceDB. If you rename either one while migrating, WoW hands Foundry an empty file: every user's existing settings are silently orphaned, and once the old TOC line is gone WoW deletes the old data at logout. Nothing in the library can detect or warn about this: the game does not expose it. Renaming the SavedVariables global is the single easiest way to destroy your users' data during a migration. Don't tidy it.
Foundry.DB replaces the common AceDB shape used by Foundry's real consumers:
profile, char, global, defaults, a shared default profile, migrations,
and logout-time default stripping.
It does not replace profile switching, namespaces, callbacks, wildcard defaults,
realm/class/faction sections, AceDBOptions, or a drop-in LibStub("AceDB-3.0")
shim.
Full reference: Foundry.DB
local defaults = {
profile = {
enabled = true,
debug = false,
},
global = {
cache = {},
},
}
function MyAddon:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, true)
self:RunMigrations()
endConstruct Foundry.DB only after your addon has finished loading:
local Lifecycle = F:RequireModule("Lifecycle", 1)
local DB = F:RequireModule("DB", 1)
local defaults = {
profile = {
enabled = true,
debug = false,
},
global = {
cache = {},
},
}
MyAddon = MyAddon or {}
MyAddon.lifecycle = Lifecycle:New(MyAddon, ADDON_NAME)
MyAddon.lifecycle:OnAddonLoaded(function(owner)
owner.db = DB:New({
name = ADDON_NAME,
sv = "MyAddonDB",
defaults = defaults,
defaultProfile = true,
})
owner:RunMigrations()
end)Use it like the AceDB sections you already know:
MyAddon.db.profile.debug = true
MyAddon.db.global.lastScan = time()
MyAddon.db.char.seenIntro = trueIf you want Foundry to own the version check, use schema:
owner.db = DB:New({
name = ADDON_NAME,
sv = "MyAddonDB",
defaults = defaults,
defaultProfile = true,
schema = {
version = 2,
key = "global.schemaVersion",
migrate = function(db, fromVersion)
if fromVersion == nil then
-- Adopt or repair an older unversioned save.
elseif fromVersion < 2 then
-- Step old data forward.
end
end,
},
})- Back up real SavedVariables before migrating.
-
defaultProfilemust be the literal valuetrue. -
nameis your TOC addon name;svis your SavedVariables global. - Construct DB after your addon's
ADDON_LOADED, not at file load time. - If you use the schema seam, the schema key must be rooted under
global. - If you use the schema seam, keep the schema stamp out of defaults.
- Unsupported AceDB APIs fail loudly instead of pretending to work.
- If your addon uses AceDB profile switching, namespaces, callbacks, wildcard defaults, or AceDBOptions, DB migration is not a one-line swap.
- The schema seam is also where downgrade protection lives (a stored version
newer than the declared one refuses construction). If you keep your own
version-stepper instead of
schema, you have no downgrade protection (the same as under AceDB), so do not assume you are covered.
Rolling back is safe. If you ship the Foundry migration and need to revert
to your old Ace3 build, users lose nothing: Foundry keeps the file in the
AceDB-shaped layout (including profileKeys), so AceDB reads it back cleanly.
Corrupt saved files refuse loudly: decide your policy before users hit it.
If a user's SavedVariables file is structurally damaged (a crash mid-write, a
hand edit), DB:New raises in both dev and release builds rather than
overwrite data. It raises on every login, until the file is fixed or deleted.
Raw Lua errors in your OnAddonLoaded handler are all the user sees unless
you decide the recovery policy yourself:
MyAddon.lifecycle:OnAddonLoaded(function(owner)
local ok, err = pcall(function()
owner.db = DB:New({
name = ADDON_NAME,
sv = "MyAddonDB",
defaults = defaults,
defaultProfile = true,
})
end)
if not ok or not owner.db then
-- The saved file is damaged. Tell the user something actionable
-- instead of letting the raw error brick the addon every login.
print("|cffff2020MyAddon:|r saved settings could not be loaded. "
.. "Delete WTF/.../SavedVariables/MyAddonDB.lua to reset.")
return
end
owner:RunMigrations()
end)Foundry deliberately ships no automatic repair (silently discarding a user's file is worse than refusing), so the choice between "instruct the user" and "reset programmatically" is yours to make, and you should make it before shipping, not after the first angry comment.
Per-character-profile addons split silently. If your AceDB call omitted the
third argument (each character gets its own profile), be aware: existing
characters keep their own saved profiles under Foundry, but characters created
after the migration land on the shared Default profile. Old characters stay
isolated, new ones share settings, and nothing warns about the split. If your
users expect per-character behavior, keep AceDB or handle it explicitly.
Namespace and extra-section data is preserved, not lost. GetNamespace,
db.realm, db.class, and friends refuse loudly, but the underlying data in
the file round-trips untouched. If you need to read old namespace data during a
migration, the raw file is reachable via the db.sv escape hatch (for example
db.sv.namespaces.MyModule).
Do not force everything through Foundry just because you are migrating some Ace3 surface.
- Keep LibDataBroker / LibDBIcon if you use minimap buttons or data objects.
- Keep CallbackHandler if you need a callback bus and already have one.
- Keep AceConfig / AceDBOptions if your options UI relies on generated widget rendering or profile management. Foundry.Settings covers panel registration only (see the Settings section above); it does not render options tables.
- Keep AceComm (and your serializer) for inter-client addon messages; Foundry has no comms module.
- AceTimer needs no library at all on modern clients: use
C_Timer.After,C_Timer.NewTimer, andC_Timer.NewTicker. - AceHook mostly maps to
hooksecurefuncfor post-hooks; for pre/raw hooks, wrap the function yourself. Foundry has no hook module. - AceLocale is a plain Lua table pattern; keep it or inline your locale table.
- Keep raw Blizzard APIs for tiny one-off cases where a Foundry controller would add more ceremony than clarity.
Foundry is meant to be adopted incrementally. Replace the part that is causing boilerplate first, verify it, then move to the next surface.