comparison Utility.lua @ 44:8913e7d79cad

Refactoring some very simple items to a Utility file
author John@Yosemite-PC
date Thu, 15 Mar 2012 22:58:54 -0400
parents
children 8856fc38cd41
comparison
equal deleted inserted replaced
43:4109683c3172 44:8913e7d79cad
1 local pairs=pairs
2 local type=type
3 local getmetatable=getmetatable
4 local setmetatable=setmetatable
5
6 setfenv(1,bsk)
7
8 -- These two functions properly format the call to AceConsole:Print(), which
9 -- needs a full object. Calling "Print" will call the mixed-in console functions
10 -- but without a self parameter because of the namespacing. I would disembed
11 -- console, except that it has handy OnDisable behavior to disable chat
12 -- commands.
13 function print(...)
14 bsk:Print(...)
15 end
16
17 function printf(...)
18 bsk:Printf(...)
19 end
20
21 function tcopy(to, from)
22 for k,v in pairs(from) do
23 if(type(v)=="table") then
24 to[k] = {}
25 tcopy(to[k], v);
26 else
27 to[k] = v;
28 end
29 end
30 end
31
32 function shallowCopy(t)
33 local u = { }
34 for k, v in pairs(t) do u[k] = v end
35 return setmetatable(u, getmetatable(t))
36 end
37
38 function PrintTable(table, depth)
39 depth = depth or ""
40 if not table then return end
41 if #depth > 3*5 then print(depth.."Recursion too deep - stopping"); return end
42 for i,v in pairs(table) do
43 if( type(v) == "string" ) then
44 print(depth .. i .. " - " .. v)
45 elseif( type(v) == "number" ) then
46 print(depth .. i .. " - " .. tostring(v))
47 elseif( type(v) == "table" ) then
48 print(depth .. i .." - ")
49 PrintTable(v,depth.." ")
50 elseif( type(v) == "boolean" ) then
51 print(depth .. i .. " - " .. tostring(v))
52 elseif( type(v) == "function" ) then
53 print(depth .. "function " .. i .. "()")
54 else
55 print(depth .. i .. " - not sure how to print type: " .. type(v) )
56 end
57 end
58 end
59