Appearance
AceConsole-3.0
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
endIn 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
| Parameter | Type | Default | Description |
|---|---|---|---|
target | table | Target object to embed AceConsole in. |
Returns
| Type | Description |
|---|---|
table | The 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
| Parameter | Type | Default | Description |
|---|---|---|---|
str | string | The raw argument string. | |
numargs (optional) | number | 1 | How many arguments to get. |
startpos (optional) | number | 1 | Where in the string to start scanning. |
Returns
| Type | Description |
|---|---|
string | One value per requested argument (numargs in total), in order. A missing argument is returned as nil. |
number | nextposition: 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)
endIterateChatCommands
method#
lua
AceConsole:IterateChatCommands()Get an iterator over all Chat Commands registered with AceConsole.
Returns
| Type | Description |
|---|---|
function | Iterator (pairs) over all commands. |
Example
lua
for command in self:IterateChatCommands() do
self:Print(command)
endPrint
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
| Parameter | Type | Default | Description |
|---|---|---|---|
chatframe (optional) | table | Custom ChatFrame to print to (or any frame with an .AddMessage function). | |
... | any | List 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
| Parameter | Type | Default | Description |
|---|---|---|---|
chatframe (optional) | table | Custom ChatFrame to print to (or any frame with an .AddMessage function). | |
format | string | Format string - same syntax as standard Lua format(). | |
... | any | Arguments 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
| Parameter | Type | Default | Description |
|---|---|---|---|
command | string | Chat command to be registered WITHOUT leading "/". | |
func | funcref | methodname | Function to call when the slash command is being used. | |
persist (optional) | boolean | true | When 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
| Type | Description |
|---|---|
boolean | true on successful registration. |
Example
lua
function MyAddon:OnEnable()
self:RegisterChatCommand("myslash", "MySlashProcessorFunc")
endUnregisterChatCommand
method#
lua
AceConsole:UnregisterChatCommand(command)Unregister a chatcommand.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
command | string | Chat command to be unregistered WITHOUT leading "/". |
