I have this running in my development addon.
Lua Code:
local tostring=tostring;
local ProxyLookup={};
local ProxyMeta={__index={
Print=function(self,...)
local frame=ProxyLookup[self];
if frame then
local msg="";
for i=1,select("#",...) do msg=(msg~="" and msg.." " or "")..tostring(select(i,...)); end
frame:AddMessage(msg);
if not frame:IsShown() then FCF_StartAlertFlash(frame); end
end
end;
Show=function(self)
local frame=ProxyLookup[self];
if frame then
local tab=_G[frame:GetName().."Tab"];
if not tab:IsShown() then
frame:Show();
tab:Show();
FCF_DockFrame(frame,#FCFDock_GetChatFrames(GENERAL_CHAT_DOCK)+1,nil);
end
end
end;
Hide=function(self)
local frame=ProxyLookup[self];
if frame then
local tab=_G[frame:GetName().."Tab"];
if tab:IsShown() then-- Mimic FCF_Close(), but don't release frame
FCF_UnDockFrame(frame);
HideUIPanel(frame);
tab:Hide();
FCF_FlagMinimizedPositionReset(frame);
if frame.minFrame and frame.minFrame:IsShown() then frame.minFrame:Hide(); end
end
end
end;
SetShown=function(self,show)
local frame=ProxyLookup[self];
if frame then self[show and "Show" or "Hide"](self); end
end;
IsShown=function()
local frame=ProxyLookup[self];
if frame then return _G[frame:GetName().."Tab"]:IsShown(); end
end;
Close=function(self)
local frame=ProxyLookup[self];
if frame then FCF_Close(frame); end
end;
}};
hooksecurefunc("FCF_Close",function(frame,other)
frame=other or frame;
local proxy=ProxyLookup[frame];
if proxy then ProxyLookup[proxy],ProxyLookup[frame]=nil,nil; end
end);
function CreateDebugMessageFrame(name,r,g,b,a)
local frame=FCF_OpenTemporaryWindow("SYSTEM");
ChatFrame_RemoveMessageGroup(frame,"SYSTEM");
FCF_SetWindowName(frame,name,true);
if r and g and b then FCF_SetWindowColor(frame,r,g,b,true); end
if a then FCF_SetWindowAlpha(frame,a,true); end
local proxy=setmetatable({},ProxyMeta);
ProxyLookup[proxy],ProxyLookup[frame]=frame,proxy;
return proxy;
end
function CreateDebugPrint(...)
local frame=CreateDebugMessageFrame(...);
return function(...) return frame:Print(...); end,frame;
end
Two global functions are available in this API,
CreateDebugMessageFrame() and
CreateDebugPrint(). The first returns a proxy object that can be used to print to and show/hide the frame as well as release the chat window to the default UI (closing it). The second quickly creates the frame and returns just the print handler function you can call to print to the window.