AceModuleCore-2.0

From WowAce Wiki
Jump to: navigation, search

Example

MyAddon = AceLibrary("AceAddon-2.0"):new("AceModuleCore-2.0")

function MyAddon.modulePrototype:Poke()
    print('ouchies')
end

local bank = MyAddon:NewModule('bank')

bank:Poke() -- ouchies

print(MyAddon:HasModule('bank')) -- true
print(MyAddon:IsModule(bank)) -- true
print(MyAddon:GetModule('bank') == bank) -- true
MyAddon:GetModule('bank'):Poke() -- ouchies

(See old doc at AceModuleCore-2.0/Autodoc)


API Documentation

Note: This documentation is auto-generated. Please note that direct modifications may be overwritten on next autogenerate.

:CallMethodOnAllModules("method" , ...)

Arguments

"method"
string - the name of the method.
...
tuple - the list of arguments to call the method with.

Notes

Safely calls the given method on all active modules if it exists on said modules. This will automatically subvert any errors that occur in the modules.

Example

core:CallMethodOnAllModules("OnSomething")
core:CallMethodOnAllModules("OnSomethingElse", 1, 2, 3, 4)

:GetModule("name")

Arguments

"name"
string - the name of the module.

Notes

Return the module "name" if it exists. If the module doesnot exist, an error is thrown.

Returns

The module requested, if it exists.

Example

local bank = core:GetModule('Bank')

:HasModule(...)

Arguments

...
list of strings that are the names of the modules. (typically you'd only check for one)

Notes

Return whether the module names given are all available in the core.

Returns

  • boolean - Whether all the modules are available in the core.

Example

if core:HasModule('Bank') then
	-- do banking
end

:IsModule(module)

Arguments

module
reference to the module

Notes

Return whether the given module is actually a module.

Returns

  • boolean - whether the given module is actually a module.

Example

if core:IsModule(module) then
	-- do something
end
-- alternatively
if AceModuleCore:IsModule(module) then
	-- checks all modules, no matter the parent
end


:IsModuleActive(module [, notLoaded])

Arguments

module
string/table - name of the module or a reference to the module
notLoaded
- boolean - if set, this will check modules that are not loaded as well. (default: false)

Notes

Returns whether the module is in an active (enabled) state. This calls module:IsActive() if available. if notLoaded is set, then "name" must be a string.

Returns

  • boolean - Whether the module is in an active (enabled) state.

Example

assert(self:IsModuleActive('bank'))

:IterateModules()

No arguments

:IterateModulesWithMethod(method)

Arguments

method
type - (needs documentation)


:NewModule("name" , ...)

Arguments

"name"
string - name/title of the Module.
...
list of mixins the module is to inherit from.

Notes

Create a new module, parented to self. The module created does, in fact, inherit from AceAddon-2.0.

Example

MyModule = core:NewModule('MyModule', "AceEvent-2.0", "AceHook-2.1")

:SetModuleDefaultState("module" , state)

Arguments

"module"
string - name of the module.
state
table - reference to the module.

Notes

Sets the default active state of a module. This should be called before the ADDON_LOADED of the module.

Example

self:SetModuleDefaultState('bank', false)

:SetModuleMixins(...)

Arguments

...
list of mixins (up to 20)

Notes

  • Sets the default mixins for a given module.
  • This cannot be called after :NewModule() has been called.
  • This should really only be called if you use the mixins in your prototype.

Example

core:SetModuleMixins("AceEvent-2.0", "AceHook-2.0")

boolean

:ToggleModuleActive(module [, state])

Arguments

module
string/table - name of the module or a reference to the module
state
boolean - new state. (default not :IsModuleActive("name" or module))

Notes

Toggles the active state of a module.

This calls module:ToggleActive([state]) if available.

If suspending, This will call :OnDisable() on the module if it is available. Also, it will iterate through the addon's mixins and call :OnEmbedDisable(module) if available. - this in turn will, through AceEvent and others, unregister events/hooks/etc. depending on the mixin. Also, it will call :OnModuleDisable(module) on the core if it is available.

If resuming, This will call :OnEnable(first) on the module if it is available. Also, it will iterate through the addon's mixins and call :OnEmbedEnable(module) if available. - this in turn will, through AceEvent and others, unregister events/hooks/etc. depending on the mixin. Also, it will call :OnModuleEnable(module) on the core if it is available.

If you call :ToggleModuleActive("name or module, true) and it is already active, it silently returns, same if you pass false and it is inactive.

Returns

  • boolean - Whether the module is now in an active (enabled) state.

Example

self:ToggleModuleActive('bank')