vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | ---- unitFromPlayerName(string name) returns string unit or false if not in group |
2 | function unitFromPlayerName(name) |
||
3 | name = string.gsub(name, "(-.*)", "") |
||
4 | |||
5 | if UnitName("player") == name then |
||
6 | return "player" |
||
7 | end |
||
8 | if GetNumRaidMembers() == 0 then |
||
9 | for i=1,GetNumPartyMembers() do |
||
10 | if(UnitName("party"..i) == name) then |
||
11 | return "party"..i |
||
12 | end |
||
13 | end |
||
14 | else |
||
15 | for i=1,GetNumRaidMembers() do |
||
16 | if(UnitName("raid"..i) == name) then |
||
17 | return "raid"..i |
||
18 | end |
||
19 | end |
||
20 | end |
||
21 | return false |
||
22 | end |
||
23 | |||
24 | function tokenizestring(str, values) |
||
25 | sgsub = string.gsub |
||
26 | for k, v in values do |
||
27 | str = sgsub(str, "%["..k.."%]", (type(v) == "function" and v() or v)) |
||
28 | end |
||
29 | return str |
||
30 | end |
||
31 | |||
32 | ---- nilTable(table tableToNil) returns empty tableToNil |
||
33 | tsetn = XLoot.compat and function() end or table.setn |
||
34 | function nilTable(tableToNil) -- MentalPower |
||
35 | if (not (type(tableToNil) == "table")) then |
||
36 | return tableToNil; |
||
37 | end |
||
38 | |||
39 | for key, value in pairs(tableToNil) do |
||
40 | if type(value) == "table" then |
||
41 | nilTable(value) |
||
42 | end |
||
43 | tableToNil[key] = nil; |
||
44 | end |
||
45 | |||
46 | tsetn(tableToNil, 0); |
||
47 | return tableToNil; |
||
48 | end |
||
49 | |||
50 | |||
51 | ---- iteratetable, rewrite of iterateTable by ckknight with fancy metatable voodoo |
||
52 | ---- for k, v in iteratetable(table, optional string key, optional boolean reverse) |
||
53 | do |
||
54 | local mySort = function(a, b) |
||
55 | if not a then |
||
56 | return false |
||
57 | end |
||
58 | if not b then |
||
59 | return true |
||
60 | end |
||
61 | |||
62 | if type(a) == "string" then |
||
63 | return string.upper(a) < string.upper(b) |
||
64 | else |
||
65 | return a < b |
||
66 | end |
||
67 | end |
||
68 | |||
69 | local mySort_reverse = function(a, b) |
||
70 | if not b then |
||
71 | return false |
||
72 | end |
||
73 | if not a then |
||
74 | return true |
||
75 | end |
||
76 | |||
77 | if type(a) == "string" then |
||
78 | return string.upper(a) > string.upper(b) |
||
79 | else |
||
80 | return a > b |
||
81 | end |
||
82 | end |
||
83 | |||
84 | local current |
||
85 | local sorts = setmetatable({}, {__index=function(self, sortBy) |
||
86 | local x = function(a, b) |
||
87 | if not a or not b then |
||
88 | return false |
||
89 | elseif type(current[a][sortBy]) == "string" then |
||
90 | return string.upper(current[a][sortBy]) < string.upper(current[b][sortBy]) |
||
91 | else |
||
92 | return current[a][sortBy] < current[b][sortBy] |
||
93 | end |
||
94 | end |
||
95 | self[sortBy] = x |
||
96 | return x |
||
97 | end}) |
||
98 | local sorts_reverse = setmetatable({}, {__index=function(self, sortBy) |
||
99 | local x = function(a, b) |
||
100 | if not a or not b then |
||
101 | return false |
||
102 | elseif type(current[a][sortBy]) == "string" then |
||
103 | return string.upper(current[a][sortBy]) > string.upper(current[b][sortBy]) |
||
104 | else |
||
105 | return current[a][sortBy] > current[b][sortBy] |
||
106 | end |
||
107 | end |
||
108 | self[sortBy] = x |
||
109 | return x |
||
110 | end}) |
||
111 | |||
112 | local iters; iters = setmetatable({}, {__index=function(self, t) |
||
113 | local q; q = function(tab) |
||
114 | local position = t['#'] + 1 |
||
115 | |||
116 | local x = t[position] |
||
117 | if not x then |
||
118 | for k in pairs(t) do |
||
119 | t[k] = nil |
||
120 | end |
||
121 | tsetn(t, 0) |
||
122 | iters[t] = q |
||
123 | return |
||
124 | end |
||
125 | |||
126 | t['#'] = position |
||
127 | |||
128 | return x, tab[x] |
||
129 | end |
||
130 | return q |
||
131 | end, __mode='k'}) |
||
132 | |||
133 | function iteratetable(tab, key, reverse) |
||
134 | local t = next(iters) or {} |
||
135 | local iter = iters[t] |
||
136 | iters[t] = nil |
||
137 | for k, v in pairs(tab) do |
||
138 | table.insert(t, k) |
||
139 | end |
||
140 | |||
141 | if not key then |
||
142 | table.sort(t, reverse and mySort_reverse or mySort) |
||
143 | else |
||
144 | current = tab |
||
145 | table.sort(t, reverse and sorts_reverse[key] or sorts[key]) |
||
146 | current = nil |
||
147 | end |
||
148 | |||
149 | t['#'] = 0 |
||
150 | |||
151 | return iter, tab |
||
152 | end |
||
153 | end |