Mercurial > wow > breuesk
view Utility.lua @ 105:c6c748a5823b tip
Collaborative list trimming 80% functional
Updates for the zone-in problem
author | John@Yosemite-PC |
---|---|
date | Sun, 06 May 2012 08:33:34 -0400 |
parents | 9aa2dcbbdc87 |
children |
line wrap: on
line source
local bsk=bsk local pairs=pairs local tostring=tostring local type=type local table=table local getmetatable=getmetatable local setmetatable=setmetatable local _G=_G setfenv(1,bsk) -- These two functions properly format the call to AceConsole:Print(), which -- needs a full object. Calling "Print" will call the mixed-in console functions -- but without a self parameter because of the namespacing. I would disembed -- console, except that it has handy OnDisable behavior to disable chat -- commands. function print(...) bsk:Print(...) end function printf(...) bsk:Printf(...) end function tcopy(to, from) if not from then to = {}; return end for k,v in pairs(from) do if(type(v)=="table") then to[k] = {} tcopy(to[k], v); else to[k] = v; end end end function shallowCopy(t) local u = { } for k, v in pairs(t) do u[k] = v end return setmetatable(u, getmetatable(t)) end function PrintTable(tabl, depth, history) depth = depth or "" history = history or {} if not tabl then return end if #depth > 3*5 then print(depth.."Recursion too deep - stopping"); return end for i,v in pairs(tabl) do if( type(v) == "string" ) then print(depth .. i .. " - " .. v) elseif( type(v) == "number" ) then if v > 1331000000 and v < 1349000000 then print(depth .. i .. " - " .. tostring(v) .. " " .. _G.date("%m/%d/%y %H:%M:%S", v)) else print(depth .. i .. " - " .. tostring(v)) end elseif( type(v) == "table" ) then --if v == table then return end print(depth .. tostring(i) .." - ") if history then for i,vh in pairs(history) do if vh==tabl then print(depth.. " - circular reference detected; halting print") return end end end table.insert(history,tabl) PrintTable(v,depth.." ",history) table.remove(history) elseif( type(v) == "boolean" ) then print(depth .. i .. " - " .. tostring(v)) elseif( type(v) == "function" ) then print(depth .. "function " .. i .. "()") else print(depth .. i .. " - not sure how to print type: " .. type(v) ) end end end