diff Devian.lua @ 72:da5ff1fc9fb6

- Fixed an issue with creating more than one output channel per UI session. - Cleanup of globals for slightly better performance when printing to a lot of channels at once
author Nenue
date Sat, 09 Apr 2016 05:51:19 -0400
parents d636ff1b17ce
children 3745540e8996
line wrap: on
line diff
--- a/Devian.lua	Mon Mar 28 02:09:53 2016 -0400
+++ b/Devian.lua	Sat Apr 09 05:51:19 2016 -0400
@@ -5,7 +5,9 @@
 
 --GLOBALS: Devian, DevCon, DevianLoadMessage
 local ADDON, D = ...
-
+local sub, GetTime, print, _G = string.sub, GetTime, print, _G
+local format, setmetatable, getprinthandler, setprinthandler = string.format, setmetatable, getprinthandler, setprinthandler
+local tinsert = tinsert
 local currentProfile
 local playerName = UnitName("player")
 local playerRealm = playerName .. '-' .. GetRealmName()
@@ -46,7 +48,7 @@
     return k
   end,
   __call = function(t,k,...)
-    return string.format((t[k] or k) , ...)
+    return format((t[k] or k) , ...)
   end
 })
 
@@ -208,7 +210,7 @@
   D.sig = {}
   D.sigID = {}
   D.IDsig = {}
-  D.dock = DevianDock
+  D.dock = _G.DevianDock
   D.dock.buttons = D.dock.buttons or {}
 
   return id, name
@@ -244,7 +246,7 @@
       D:Print("Profile |cFFFFFF00".. list_id .."|r saved.")
     else
 
-      DevianLoadMessage = "Switched profiles."
+      _G.DevianLoadMessage = "Switched profiles."
 
       list_id = tonumber(mode)
       if list_id ~= db.main_profile then
@@ -255,7 +257,7 @@
     end
   elseif mode == nil then
     list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile
-    DevianLoadMessage = "Switched between main and recent profile ("..db.current_profile..' and '..list_id..')'
+    _G.DevianLoadMessage = "Switched between main and recent profile ("..db.current_profile..' and '..list_id..')'
     db.current_profile = list_id
     scan_func = D.Load
   else
@@ -276,7 +278,7 @@
   end
 
   if scan_func == D.Load then
-    ReloadUI()
+    _G.ReloadUI()
   end
   D.Profile(db.current_profile)
 end
@@ -375,6 +377,7 @@
 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint().
 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel.
 -- @param ... Output contents.
+
 function D.Message(prefix, ...)
   if not currentProfile.workspace then
     return D.oldprint(prefix, ...)
@@ -424,17 +427,17 @@
 
     if type(var) == 'table' then
       if type(var.GetName) == 'function' then
-        var = '<table:'..tostring(var:GetName())..'>'
+        var = '[table:'..tostring(var:GetName())..']'
       else
         var = '<'..tostring(var)..'>'
       end
 
     elseif type(var) == 'boolean' then
-      var = var and 'true' or 'false'
+      var = var and '[true]' or '[false]'
     elseif type(var) == 'function' then
-      var = '<funcref>'
+      var = '['..tostring(var)..']'
     elseif type(var) == 'nil' then
-      var = 'nil'
+      var = '[nil]'
     else
       var = tostring(var)
     end
@@ -444,7 +447,7 @@
   local message = concat(buffer, ' ')
   for id, channel in pairs(sendq) do
     if channel.width < 250 then
-      prefix = string.sub(prefix, 0,2)
+      prefix = sub(prefix, 0,2)
     end
     channel.out:AddMessage('|cFF'.. pcolor..prefix ..'|r ' .. message, 0.8, 0.8, 0.8, nil, nil, prefix, GetTime())
     if not D.dock.buttons[id].newMessage then
@@ -469,6 +472,7 @@
 
 local blocked = {profiles = true, debugmode = true}
 D.SetDefaults = function()
+  local DevianDB = _G.DevianDB
   for k,v in pairs(DevianDB) do
     if not blocked[k] then
       DevianDB[k] = nil
@@ -479,13 +483,13 @@
       DevianDB[k] = v
     end
   end
-  DevianLoadMessage = "Non-user SavedVars have been reset."
-  ReloadUI()
+  _G.DevianLoadMessage = "Non-user SavedVars have been reset."
+  _G.ReloadUI()
 end
 D.SetDefaultsAll = function ()
-  DevianDB = nil
-  DevianLoadMessage = "All SavedVars wiped."
-  ReloadUI()
+  _G.DevianDB = nil
+  _G.DevianLoadMessage = "All SavedVars wiped."
+  _G.ReloadUI()
 end
 D.ConfigCommand = function(self, input)
   if not self.config then
@@ -499,6 +503,7 @@
 
   -- commands
   local cmdlist = {
+    ['dfs'] = 'FrameHelper_Update',
     ['dvn'] = "Command",
     ['devian'] = "Command",
     ['dvc'] = "Console_Toggle",
@@ -521,9 +526,9 @@
   self.db = db
 
   ---
-  if DevianLoadMessage then
-    D:Print(DevianLoadMessage)
-    DevianLoadMessage = nil
+  if _G.DevianLoadMessage then
+    D:Print(_G.DevianLoadMessage)
+    _G.DevianLoadMessage = nil
   end
 
 
@@ -557,7 +562,7 @@
       D.console[currentProfile.current_channel]:ToFront()
       -- bring the current channel to the front
     end
-    DevianDock:Show()
+    _G.DevianDock:Show()
     D:UpdateDock()
   end
 end