EmbedHandler-1.0

object:Embed(target [, exceptions])

Embeds the methods from one object into the given target, with optional exceptions.

Returns

The target on which the methods were embedded

Parameters

target
The object to be embedded
exceptions
Methods not to be embedded, or non-method indexes to be embedded

Usage

-- Embeds methods from EmbedHandler into "MyObject"
LibStub("EmbedHandler-1.0"):Embed(MyObject)
MyObject.SomeIndex = 5

function MyObject:SomeMethod()
  -- Some Method
end

function MyObject:OtherMethod()
  -- Other Method
end

-- Embeds all methods from MyObject into an empty
-- table with the exception of "SomeMethod".
-- The non-method "SomeIndex" is also embedded
local OtherObject = MyObject:Embed({}, "SomeMethod", "SomeIndex")


object:SpecificEmbed(target [, indexes])

Embeds the specified indexes from one object into the given target. Useful if you only want to embed some methods from one object into another.

Returns

The target on which the methods were embedded

Parameters

target
The object to be embedded
indexes
Indexes to be embedded on the target

Usage

-- Embeds methods from EmbedHandler into "MyObject"
LibStub("EmbedHandler-1.0"):Embed(MyObject)
MyObject.SomeIndex = 5

function MyObject:SomeMethod()
  -- Some Method
end

-- Embeds "SomeIndex" and "SomeMethod" into a new empty table
local OtherObject = MyObject:Embed({}, "SomeMethod", "SomeIndex")


object:IterateEmbeds()

Return an iterator of all targets which were embedded with methods (or indexes) from the given object

Usage

-- "Tag" all targets embedded with "MyObject"
for target in MyObject:IterateEmbeds() do
  target.embedded_by_MyObject = true
end


object:UpdateEmbeds()

Re-embeds all targets which were embedded with methods (or indexes) from the given object. May be useful, for example, to libraries which need to update objects with updated methods from a new version.

Usage

-- Embed "MyObject" into 2 different targets
MyObject:Embed(FirstTarget)
MyObject:Embed(SecondTarget)

-- Define a new method
function MyObject:SomeMethod()
  -- Some Method
end

-- Make the 2 targets aware of "SomeMethod"
MyObject:UpdateEmbeds()

print(FirstTarget.SomeMethod == MyObject.SomeMethod)
-- prints true