AceConsole.commands = AceConsole.commands or {} -- table containing commands registered |
AceConsole.weakcommands = AceConsole.weakcommands or {} -- table containing self, command => func references for weak commands that don't persist through enable/disable |
|
-- local upvalues |
local _G = _G |
local pairs = pairs |
local select = select |
local type = type |
local tostring = tostring |
local strfind = string.find |
local strsub = string.sub |
-- Lua APIs |
local tconcat, tostring, select = table.concat, tostring, select |
local type, pairs, error = type, pairs, error |
local format, strfind, strsub = string.format, string.find, string.sub |
local max = math.max |
|
-- AceConsole:Print( [chatframe,] ... ) |
-- |
-- Print to DEFAULT_CHAT_FRAME or given chatframe (anything with an .AddMessage member) |
function AceConsole:Print(...) |
local text = "" |
-- WoW APIs |
local _G = _G |
|
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: DEFAULT_CHAT_FRAME, SlashCmdList, hash_SlashCmdList |
|
local tmp={} |
local function Print(self,frame,...) |
local n=0 |
if self ~= AceConsole then |
text = "|cff33ff99"..tostring( self ).."|r: " |
n=n+1 |
tmp[n] = "|cff33ff99"..tostring( self ).."|r:" |
end |
for i=1, select("#", ...) do |
n=n+1 |
tmp[n] = tostring(select(i, ...)) |
end |
frame:AddMessage( tconcat(tmp," ",1,n) ) |
end |
|
local frame = select(1, ...) |
if not ( type(frame) == "table" and frame.AddMessage ) then -- Is first argument something with an .AddMessage member? |
frame=nil |
--- Print to DEFAULT_CHAT_FRAME or given ChatFrame (anything with an .AddMessage function) |
-- @paramsig [chatframe ,] ... |
-- @param chatframe Custom ChatFrame to print to (or any frame with an .AddMessage function) |
-- @param ... List of any values to be printed |
function AceConsole:Print(...) |
local frame = ... |
if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member? |
return Print(self, frame, select(2,...)) |
else |
return Print(self, DEFAULT_CHAT_FRAME, ...) |
end |
|
for i=(frame and 2 or 1), select("#", ...) do |
text = text .. tostring( select( i, ...) ) .." " |
end |
|
|
--- Formatted (using format()) print to DEFAULT_CHAT_FRAME or given ChatFrame (anything with an .AddMessage function) |
-- @paramsig [chatframe ,] "format"[, ...] |
-- @param chatframe Custom ChatFrame to print to (or any frame with an .AddMessage function) |
-- @param format Format string - same syntax as standard Lua format() |
-- @param ... Arguments to the format string |
function AceConsole:Printf(...) |
local frame = ... |
if type(frame) == "table" and frame.AddMessage then -- Is first argument something with an .AddMessage member? |
return Print(self, frame, format(select(2,...))) |
else |
return Print(self, DEFAULT_CHAT_FRAME, format(...)) |
end |
(frame or DEFAULT_CHAT_FRAME):AddMessage( text ) |
end |
|
|
-- AceConsole:RegisterChatCommand(. command, func, persist ) |
-- |
-- command (string) - chat command to be registered WITHOUT leading "/" |
-- func (function|membername) - function to call, or self[membername](self, ...) call |
-- persist (boolean) - false: the command will be soft disabled/enabled when aceconsole is used as a mixin (default: true) |
-- |
-- Register a simple chat command |
|
|
--- Register a simple chat command |
-- @param command Chat command to be registered WITHOUT leading "/" |
-- @param func Function to call when the slash command is being used (funcref or methodname) |
-- @param persist if false, the command will be soft disabled/enabled when aceconsole is used as a mixin (default: true) |
function AceConsole:RegisterChatCommand( command, func, persist ) |
if type(command)~="string" then error([[Usage: AceConsole:RegisterChatCommand( "command", func[, persist ]): 'command' - expected a string]], 2) end |
|