Embed (Mixin)
From WowAce Wiki
Were you looking for another definition of embedding?
Embedding a library into an addon, also known as mixing-in, basically means to take the methods in a library and copy them onto another object (table).
Some libraries will alter their function names when embedding to make them unique. Others will only embed some of their functions. Yet others will embed extra functions not normally available when accessed directly via the library object.
Reasons for doing so vary, but when embedding is optional, benefits commonly include:
- Ability to automatically shutdown library subsystems when the addon disables to save CPU resources
- Ability to automatically deregister anything the addon requested from the library (timers, events) when the addon disables, without the addon having to remember them all manually
- Better error reporting
In a few cases, embedding is not optional for a library -- it might need the 'self' reference to be a live object of some kind, for example a frame. This could be the case for e.g. a window manager.
Embedding in Ace3
A library capable of being embedded will publish an ":Embed(destination)" method according to the Ace3 specification. Not all libraries are capable of being embedded though, and will not publish it. Any libstub-based library with an :Embed() can automatically be embedded by AceAddon on addon object creation.
Embedding a library into an addon object when it is being created:
local myAddon = LibStub("AceAddon-3.0"):NewAddon("myAddon", "MyLibrary-1.2", ... )
Embedding a library into something already-existing:
LibStub("MyLibrary-1.2"):Embed(myTable)
Ace3 libraries are expected to track their embed locations and update them if/when the library is upgraded in-game (by finding a newer version to load). Read more under LibStub.

