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@44
|
25 for k,v in pairs(from) do
|
John@44
|
26 if(type(v)=="table") then
|
John@44
|
27 to[k] = {}
|
John@44
|
28 tcopy(to[k], v);
|
John@44
|
29 else
|
John@44
|
30 to[k] = v;
|
John@44
|
31 end
|
John@44
|
32 end
|
John@44
|
33 end
|
John@44
|
34
|
John@44
|
35 function shallowCopy(t)
|
John@44
|
36 local u = { }
|
John@44
|
37 for k, v in pairs(t) do u[k] = v end
|
John@44
|
38 return setmetatable(u, getmetatable(t))
|
John@44
|
39 end
|
John@44
|
40
|
John@62
|
41 function PrintTable(tabl, depth, history)
|
John@44
|
42 depth = depth or ""
|
John@62
|
43 history = history or {}
|
John@62
|
44 if not tabl then return end
|
John@44
|
45 if #depth > 3*5 then print(depth.."Recursion too deep - stopping"); return end
|
John@62
|
46 for i,v in pairs(tabl) do
|
John@44
|
47 if( type(v) == "string" ) then
|
John@44
|
48 print(depth .. i .. " - " .. v)
|
John@44
|
49 elseif( type(v) == "number" ) then
|
John@44
|
50 print(depth .. i .. " - " .. tostring(v))
|
John@44
|
51 elseif( type(v) == "table" ) then
|
John@48
|
52 --if v == table then return end
|
John@48
|
53 print(depth .. tostring(i) .." - ")
|
John@62
|
54 if history then
|
John@62
|
55 for i,vh in pairs(history) do
|
John@62
|
56 if vh==tabl then
|
John@62
|
57 print(depth.. " - circular reference detected; halting print")
|
John@62
|
58 return
|
John@62
|
59 end
|
John@62
|
60 end
|
John@62
|
61 end
|
John@62
|
62 table.insert(history,tabl)
|
John@62
|
63 PrintTable(v,depth.." ",history)
|
John@62
|
64 table.remove(history)
|
John@44
|
65 elseif( type(v) == "boolean" ) then
|
John@44
|
66 print(depth .. i .. " - " .. tostring(v))
|
John@44
|
67 elseif( type(v) == "function" ) then
|
John@44
|
68 print(depth .. "function " .. i .. "()")
|
John@44
|
69 else
|
John@44
|
70 print(depth .. i .. " - not sure how to print type: " .. type(v) )
|
John@44
|
71 end
|
John@44
|
72 end
|
John@44
|
73 end
|
John@44
|
74
|