annotate Utility.lua @ 103:d3ea0ab1428d

Bad commit, ignore. Just want a (failed) path to be on record.
author John@Doomsday
date Thu, 03 May 2012 09:05:40 -0400
parents 790266dbcaff
children 9aa2dcbbdc87
rev   line source
John@47 1 local bsk=bsk
John@44 2 local pairs=pairs
John@47 3 local tostring=tostring
John@44 4 local type=type
John@62 5 local table=table
John@44 6 local getmetatable=getmetatable
John@44 7 local setmetatable=setmetatable
John@44 8
John@44 9 setfenv(1,bsk)
John@44 10
John@44 11 -- These two functions properly format the call to AceConsole:Print(), which
John@44 12 -- needs a full object. Calling "Print" will call the mixed-in console functions
John@44 13 -- but without a self parameter because of the namespacing. I would disembed
John@44 14 -- console, except that it has handy OnDisable behavior to disable chat
John@44 15 -- commands.
John@44 16 function print(...)
John@44 17 bsk:Print(...)
John@44 18 end
John@44 19
John@44 20 function printf(...)
John@44 21 bsk:Printf(...)
John@44 22 end
John@44 23
John@44 24 function tcopy(to, from)
John@100 25 if not from then to = {}; return end
John@100 26 for k,v in pairs(from) do
John@100 27 if(type(v)=="table") then
John@100 28 to[k] = {}
John@100 29 tcopy(to[k], v);
John@100 30 else
John@100 31 to[k] = v;
John@100 32 end
John@44 33 end
John@44 34 end
John@44 35
John@44 36 function shallowCopy(t)
John@44 37 local u = { }
John@44 38 for k, v in pairs(t) do u[k] = v end
John@44 39 return setmetatable(u, getmetatable(t))
John@44 40 end
John@44 41
John@62 42 function PrintTable(tabl, depth, history)
John@44 43 depth = depth or ""
John@62 44 history = history or {}
John@62 45 if not tabl then return end
John@44 46 if #depth > 3*5 then print(depth.."Recursion too deep - stopping"); return end
John@62 47 for i,v in pairs(tabl) do
John@44 48 if( type(v) == "string" ) then
John@44 49 print(depth .. i .. " - " .. v)
John@44 50 elseif( type(v) == "number" ) then
John@44 51 print(depth .. i .. " - " .. tostring(v))
John@44 52 elseif( type(v) == "table" ) then
John@48 53 --if v == table then return end
John@48 54 print(depth .. tostring(i) .." - ")
John@62 55 if history then
John@62 56 for i,vh in pairs(history) do
John@62 57 if vh==tabl then
John@62 58 print(depth.. " - circular reference detected; halting print")
John@62 59 return
John@62 60 end
John@62 61 end
John@62 62 end
John@62 63 table.insert(history,tabl)
John@62 64 PrintTable(v,depth.." ",history)
John@62 65 table.remove(history)
John@44 66 elseif( type(v) == "boolean" ) then
John@44 67 print(depth .. i .. " - " .. tostring(v))
John@44 68 elseif( type(v) == "function" ) then
John@44 69 print(depth .. "function " .. i .. "()")
John@44 70 else
John@44 71 print(depth .. i .. " - not sure how to print type: " .. type(v) )
John@44 72 end
John@44 73 end
John@44 74 end
John@44 75