Skip to content

AceConsole-3.0

embeddable This library can be embedded into your addon as a mixin; list it when you create the addon and its methods become available directly on your addon object (via self).
Creating an addon object →

AceConsole-3.0 provides registration facilities for slash commands. You can register slash commands to your custom functions and use the GetArgs function to parse them to your addons individual needs.

Usage

Output

Call :Print with the text to output. As a mixin it's available on your addon object:

lua
-- AceConsole used as a mixin
MyAddon:Print("Hello, world!")

-- print to a specific chat frame
MyAddon:Print(ChatFrame1, "Hello, World!")

Slash commands

Register a command (without the leading slash) and a handler (a method name or a function):

lua
MyAddon:RegisterChatCommand("myslash", "MySlashProcessorFunc")

function MyAddon:MySlashProcessorFunc(input)
    -- 'input' contains whatever follows the slash command
end

In many cases it's simpler to let AceConfig generate slash commands automatically.

API Reference

Embed

method#
lua
AceConsole:Embed(target)

Copies AceConsole's methods onto target so you can call them on it directly. See The :Embed method.

Parameters

ParameterTypeDefaultDescription
targettableTarget object to embed AceConsole in.

Returns

TypeDescription
tableThe target object that was embedded.

Example

lua
LibStub("AceConsole-3.0"):Embed(MyObject)

GetArgs

method#
lua
AceConsole:GetArgs(str, numargs?, startpos?)

Retrieve one or more space-separated arguments from a string.

Treats quoted strings and itemlinks as non-spaced.

Parameters

ParameterTypeDefaultDescription
strstringThe raw argument string.
numargs (optional)number1How many arguments to get.
startpos (optional)number1Where in the string to start scanning.

Returns

TypeDescription
stringOne value per requested argument (numargs in total), in order. A missing argument is returned as nil.
numbernextposition: Returned after the arguments: the position in the string just after the last parsed argument, to feed back as startpos. Returned as 1e9 once the end of the string is reached.

Example

lua
function MyAddon:MySlashProcessorFunc(input)
    local arg1, arg2 = self:GetArgs(input, 2)
end

IterateChatCommands

method#
lua
AceConsole:IterateChatCommands()

Get an iterator over all Chat Commands registered with AceConsole.

Returns

TypeDescription
functionIterator (pairs) over all commands.

Example

lua
for command in self:IterateChatCommands() do
    self:Print(command)
end

Print

method#
lua
AceConsole:Print(chatframe?, ...)

Print to DEFAULT_CHAT_FRAME or given ChatFrame (anything with an .AddMessage function).

chatframe is not a true positional argument: Print takes only ... and inspects the first value. If it is a table with an .AddMessage method it is used as the target frame; otherwise it is treated as the first value to print and output goes to DEFAULT_CHAT_FRAME.

Parameters

ParameterTypeDefaultDescription
chatframe (optional)tableCustom ChatFrame to print to (or any frame with an .AddMessage function).
...anyList of any values to be printed.

Printf

method#
lua
AceConsole:Printf(chatframe?, format, ...)

Formatted (using format()) print to DEFAULT_CHAT_FRAME or given ChatFrame (anything with an .AddMessage function).

As with :Print, chatframe is detected by type rather than position: the first argument is used as the target frame only if it is a table with an .AddMessage method, otherwise it is taken as the format string.

Parameters

ParameterTypeDefaultDescription
chatframe (optional)tableCustom ChatFrame to print to (or any frame with an .AddMessage function).
formatstringFormat string - same syntax as standard Lua format().
...anyArguments to the format string.

RegisterChatCommand

method#
lua
AceConsole:RegisterChatCommand(command, func, persist?)

Register a simple chat command. Sets up the SlashCmdList entry and the SLASH_*1 global for the command. If func is a string it is treated as a method name and invoked on the embedding object (self); otherwise it is used directly as the handler. Non-persisting commands are tracked so they can be re-registered/unregistered as the addon is enabled/disabled.

Parameters

ParameterTypeDefaultDescription
commandstringChat command to be registered WITHOUT leading "/".
funcfuncref | methodnameFunction to call when the slash command is being used.
persist (optional)booleantrueWhen false, the command is tied to your addon's enabled state: AceConsole registers it when the addon (or module) is enabled and unregisters it when disabled. This only takes effect when AceConsole is embedded as a mixin, since the enable/disable hooks come from AceAddon. The default true keeps the command registered for the whole session.

Returns

TypeDescription
booleantrue on successful registration.

Example

lua
function MyAddon:OnEnable()
    self:RegisterChatCommand("myslash", "MySlashProcessorFunc")
end

UnregisterChatCommand

method#
lua
AceConsole:UnregisterChatCommand(command)

Unregister a chatcommand.

Parameters

ParameterTypeDefaultDescription
commandstringChat command to be unregistered WITHOUT leading "/".

Ace3, a World of Warcraft addon framework.