vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local MAJOR_VERSION = "Core 1.1" |
2 | local MINOR_VERSION = tonumber(string.sub("$Revision: 2023 $", 12, -3)) |
||
3 | |||
4 | if BabbleLib and BabbleLib.versions[MAJOR_VERSION] and BabbleLib.versions[MAJOR_VERSION].minor >= MINOR_VERSION then |
||
5 | return |
||
6 | end |
||
7 | |||
8 | local locale = GetLocale and GetLocale() or "enUS" |
||
9 | if locale ~= "frFR" and locale ~= "deDE" and locale ~= "zhCN" then |
||
10 | locale = "enUS" |
||
11 | end |
||
12 | |||
13 | -------------IRIEL'S-STUB-CODE-------------- |
||
14 | local stub = {}; |
||
15 | |||
16 | -- Instance replacement method, replace contents of old with that of new |
||
17 | function stub:ReplaceInstance(old, new) |
||
18 | for k,v in pairs(old) do old[k]=nil; end |
||
19 | for k,v in pairs(new) do old[k]=v; end |
||
20 | end |
||
21 | |||
22 | -- Get a new copy of the stub |
||
23 | function stub:NewStub() |
||
24 | local newStub = {}; |
||
25 | self:ReplaceInstance(newStub, self); |
||
26 | newStub.lastVersion = ''; |
||
27 | newStub.versions = {}; |
||
28 | return newStub; |
||
29 | end |
||
30 | |||
31 | -- Get instance version |
||
32 | function stub:GetInstance(version) |
||
33 | if (not version) then version = self.lastVersion; end |
||
34 | local versionData = self.versions[version]; |
||
35 | if (not versionData) then |
||
36 | message("Cannot find library instance with version '" |
||
37 | .. version .. "'"); |
||
38 | return; |
||
39 | end |
||
40 | return versionData.instance; |
||
41 | end |
||
42 | |||
43 | -- Register new instance |
||
44 | function stub:Register(newInstance) |
||
45 | local version,minor = newInstance:GetLibraryVersion(); |
||
46 | self.lastVersion = version; |
||
47 | local versionData = self.versions[version]; |
||
48 | if (not versionData) then |
||
49 | -- This one is new! |
||
50 | versionData = { instance = newInstance, |
||
51 | minor = minor, |
||
52 | old = {} |
||
53 | }; |
||
54 | self.versions[version] = versionData; |
||
55 | newInstance:LibActivate(self); |
||
56 | return newInstance; |
||
57 | end |
||
58 | if (minor <= versionData.minor) then |
||
59 | -- This one is already obsolete |
||
60 | if (newInstance.LibDiscard) then |
||
61 | newInstance:LibDiscard(); |
||
62 | end |
||
63 | return versionData.instance; |
||
64 | end |
||
65 | -- This is an update |
||
66 | local oldInstance = versionData.instance; |
||
67 | local oldList = versionData.old; |
||
68 | versionData.instance = newInstance; |
||
69 | versionData.minor = minor; |
||
70 | local skipCopy = newInstance:LibActivate(self, oldInstance, oldList); |
||
71 | table.insert(oldList, oldInstance); |
||
72 | if (not skipCopy) then |
||
73 | for i, old in ipairs(oldList) do |
||
74 | self:ReplaceInstance(old, newInstance); |
||
75 | end |
||
76 | end |
||
77 | return newInstance; |
||
78 | end |
||
79 | |||
80 | -- Bind stub to global scope if it's not already there |
||
81 | if (not BabbleLib) then |
||
82 | BabbleLib = stub:NewStub(); |
||
83 | end |
||
84 | |||
85 | -- Nil stub for garbage collection |
||
86 | stub = nil; |
||
87 | -----------END-IRIEL'S-STUB-CODE------------ |
||
88 | |||
89 | local function assert(condition, message) |
||
90 | if not condition then |
||
91 | local stack = debugstack() |
||
92 | local first = string.gsub(stack, "\n.*", "") |
||
93 | local file = string.gsub(first, "^(.*\\.*).lua:%d+: .*", "%1") |
||
94 | file = string.gsub(file, "([%(%)%.%*%+%-%[%]%?%^%$%%])", "%%%1") |
||
95 | if not message then |
||
96 | local _,_,second = string.find(stack, "\n(.-)\n") |
||
97 | message = "assertion failed! " .. second |
||
98 | end |
||
99 | message = "BabbleLib-Core: " .. message |
||
100 | local i = 1 |
||
101 | for s in string.gfind(stack, "\n(.-)\n") do |
||
102 | i = i + 1 |
||
103 | if not string.find(s, file .. "%.lua:%d+:") then |
||
104 | error(message, i) |
||
105 | return |
||
106 | end |
||
107 | end |
||
108 | print('bravo') |
||
109 | error(message, 2) |
||
110 | return |
||
111 | end |
||
112 | return condition |
||
113 | end |
||
114 | |||
115 | local lib = {} |
||
116 | |||
117 | do |
||
118 | local sequences = { |
||
119 | ["%d*d"] = "%%d+", |
||
120 | ["s"] = ".+", |
||
121 | ["[fg]"] = "%%d+%%.%%d+", |
||
122 | ["%.%d[fg]"] = "%%d+%%.%%d+", |
||
123 | ["c"] = ".", |
||
124 | } |
||
125 | local curries = {} |
||
126 | |||
127 | local function doNothing(item) |
||
128 | return item |
||
129 | end |
||
130 | local v = {} |
||
131 | |||
132 | local function concat(a1, a2, a3, a4) |
||
133 | local left, right |
||
134 | if not a2 then |
||
135 | return a1 |
||
136 | elseif not a3 then |
||
137 | left, right = a1, a2 |
||
138 | elseif not a4 then |
||
139 | return concat(concat(a1, a2), a3) |
||
140 | else |
||
141 | return concat(concat(concat(a1, a2), a3), a4) |
||
142 | end |
||
143 | if not string.find(left, "%%1%$") and not string.find(right, "%%1%$") then |
||
144 | return left .. right |
||
145 | elseif not string.find(right, "%%1%$") then |
||
146 | local i |
||
147 | for j = 9, 1, -1 do |
||
148 | if string.find(left, "%%" .. j .. "%$") then |
||
149 | i = j |
||
150 | break |
||
151 | end |
||
152 | end |
||
153 | while true do |
||
154 | local first |
||
155 | local firstPat |
||
156 | for x, y in pairs(sequences) do |
||
157 | local i = string.find(right, "%%" .. x) |
||
158 | if not first or (i and i < first) then |
||
159 | first = i |
||
160 | firstPat = x |
||
161 | end |
||
162 | end |
||
163 | if not first then |
||
164 | break |
||
165 | end |
||
166 | i = i + 1 |
||
167 | right = string.gsub(right, "%%(" .. firstPat .. ")", "%%" .. i .. "$%1") |
||
168 | end |
||
169 | return left .. right |
||
170 | elseif not string.find(left, "%%1%$") then |
||
171 | local i = 1 |
||
172 | while true do |
||
173 | local first |
||
174 | local firstPat |
||
175 | for x, y in pairs(sequences) do |
||
176 | local i = string.find(left, "%%" .. x) |
||
177 | if not first or (i and i < first) then |
||
178 | first = i |
||
179 | firstPat = x |
||
180 | end |
||
181 | end |
||
182 | if not first then |
||
183 | break |
||
184 | end |
||
185 | i = i + 1 |
||
186 | left = string.gsub(left, "%%(" .. firstPat .. ")", "%%" .. i .. "$%1") |
||
187 | end |
||
188 | return concat(left, right) |
||
189 | else |
||
190 | local i |
||
191 | for j = 9, 1, -1 do |
||
192 | if string.find(left, "%%" .. j .. "%$") then |
||
193 | i = j |
||
194 | break |
||
195 | end |
||
196 | end |
||
197 | local j |
||
198 | for k = 9, 1, -1 do |
||
199 | if string.find(right, "%%" .. k .. "%$") then |
||
200 | j = k |
||
201 | break |
||
202 | end |
||
203 | end |
||
204 | for k = j, 1, -1 do |
||
205 | right = string.gsub(right, "%%" .. k .. "%$", "%%" .. k + i .. "%$") |
||
206 | end |
||
207 | return left .. right |
||
208 | end |
||
209 | end |
||
210 | |||
211 | local function Curry(a1, a2, a3, a4) |
||
212 | local pattern = concat(a1, a2, a3, a4) |
||
213 | assert(pattern, "No pattern given") |
||
214 | if not string.find(pattern, "%%1%$") then |
||
215 | local unpattern = string.gsub(pattern, "([%(%)%.%*%+%-%[%]%?%^%$%%])", "%%%1") |
||
216 | local f = {} |
||
217 | local i = 0 |
||
218 | while true do |
||
219 | local first |
||
220 | local firstPat |
||
221 | for x, y in pairs(sequences) do |
||
222 | local i = string.find(unpattern, "%%%%" .. x) |
||
223 | if not first or (i and i < first) then |
||
224 | first = i |
||
225 | firstPat = x |
||
226 | end |
||
227 | end |
||
228 | if not first then |
||
229 | break |
||
230 | end |
||
231 | unpattern = string.gsub(unpattern, "%%%%" .. firstPat, "(" .. sequences[firstPat] .. ")", 1) |
||
232 | i = i + 1 |
||
233 | if firstPat == "c" or firstPat == "s" then |
||
234 | table.insert(f, doNothing) |
||
235 | else |
||
236 | table.insert(f, tonumber) |
||
237 | end |
||
238 | end |
||
239 | unpattern = "^" .. unpattern .. "$" |
||
240 | local _,alpha, bravo, charlie, delta, echo, foxtrot, golf, hotel, india |
||
241 | if i == 0 then |
||
242 | return |
||
243 | elseif i == 1 then |
||
244 | return function(text) |
||
245 | _,_,alpha = string.find(text, unpattern) |
||
246 | if alpha then |
||
247 | return f[1](alpha) |
||
248 | end |
||
249 | end |
||
250 | elseif i == 2 then |
||
251 | return function(text) |
||
252 | _,_,alpha, bravo = string.find(text, unpattern) |
||
253 | if alpha then |
||
254 | return f[1](alpha), f[2](bravo) |
||
255 | end |
||
256 | end |
||
257 | elseif i == 3 then |
||
258 | return function(text) |
||
259 | _,_,alpha, bravo, charlie = string.find(text, unpattern) |
||
260 | if alpha then |
||
261 | return f[1](alpha), f[2](bravo), f[3](charlie) |
||
262 | end |
||
263 | end |
||
264 | elseif i == 4 then |
||
265 | return function(text) |
||
266 | _,_,alpha, bravo, charlie, delta = string.find(text, unpattern) |
||
267 | if alpha then |
||
268 | return f[1](alpha), f[2](bravo), f[3](charlie), f[4](delta) |
||
269 | end |
||
270 | end |
||
271 | elseif i == 5 then |
||
272 | return function(text) |
||
273 | _,_,alpha, bravo, charlie, delta, echo = string.find(text, unpattern) |
||
274 | if alpha then |
||
275 | return f[1](alpha), f[2](bravo), f[3](charlie), f[4](delta), f[5](echo) |
||
276 | end |
||
277 | end |
||
278 | elseif i == 6 then |
||
279 | return function(text) |
||
280 | _,_,alpha, bravo, charlie, delta, echo, foxtrot = string.find(text, unpattern) |
||
281 | if alpha then |
||
282 | return f[1](alpha), f[2](bravo), f[3](charlie), f[4](delta), f[5](echo), f[6](foxtrot) |
||
283 | end |
||
284 | end |
||
285 | elseif i == 7 then |
||
286 | return function(text) |
||
287 | _,_,alpha, bravo, charlie, delta, echo, foxtrot, golf = string.find(text, unpattern) |
||
288 | if alpha then |
||
289 | return f[1](alpha), f[2](bravo), f[3](charlie), f[4](delta), f[5](echo), f[6](foxtrot), f[7](golf) |
||
290 | end |
||
291 | end |
||
292 | elseif i == 8 then |
||
293 | return function(text) |
||
294 | _,_,alpha, bravo, charlie, delta, echo, foxtrot, golf, hotel = string.find(text, unpattern) |
||
295 | if alpha then |
||
296 | return f[1](alpha), f[2](bravo), f[3](charlie), f[4](delta), f[5](echo), f[6](foxtrot), f[7](golf), f[8](hotel) |
||
297 | end |
||
298 | end |
||
299 | else |
||
300 | return function(text) |
||
301 | _,_,alpha, bravo, charlie, delta, echo, foxtrot, golf, hotel, india = string.find(text, unpattern) |
||
302 | if alpha then |
||
303 | return f[1](alpha), f[2](bravo), f[3](charlie), f[4](delta), f[5](echo), f[6](foxtrot), f[7](golf), f[8](hotel), f[9](india) |
||
304 | end |
||
305 | end |
||
306 | end |
||
307 | else |
||
308 | local o = {} |
||
309 | local f = {} |
||
310 | local unpattern = string.gsub(pattern, "([%(%)%.%*%+%-%[%]%?%^%$%%])", "%%%1") |
||
311 | local i = 1 |
||
312 | while true do |
||
313 | local pat |
||
314 | for x, y in pairs(sequences) do |
||
315 | if not pat and string.find(unpattern, "%%%%" .. i .. "%%%$" .. x) then |
||
316 | pat = x |
||
317 | break |
||
318 | end |
||
319 | end |
||
320 | if not pat then |
||
321 | break |
||
322 | end |
||
323 | unpattern = string.gsub(unpattern, "%%%%" .. i .. "%%%$" .. pat, "(" .. sequences[pat] .. ")", 1) |
||
324 | if pat == "c" or pat == "s" then |
||
325 | table.insert(f, doNothing) |
||
326 | else |
||
327 | table.insert(f, tonumber) |
||
328 | end |
||
329 | i = i + 1 |
||
330 | end |
||
331 | i = 1 |
||
332 | string.gsub(pattern, "%%(%d)%$", function(w) o[i] = tonumber(w); i = i + 1; end) |
||
333 | v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9] = nil |
||
334 | for x, y in pairs(f) do |
||
335 | v[x] = f[y] |
||
336 | end |
||
337 | for x, y in pairs(v) do |
||
338 | f[x] = v[x] |
||
339 | end |
||
340 | unpattern = "^" .. unpattern .. "$" |
||
341 | i = i - 1 |
||
342 | if i == 0 then |
||
343 | return function(text) |
||
344 | return |
||
345 | end |
||
346 | elseif i == 1 then |
||
347 | return function(text) |
||
348 | _,_,v[1] = string.find(text, unpattern) |
||
349 | if v[1] then |
||
350 | return f[1](v[1]) |
||
351 | end |
||
352 | end |
||
353 | elseif i == 2 then |
||
354 | return function(text) |
||
355 | _,_,v[1],v[2] = string.find(text, unpattern) |
||
356 | if v[1] then |
||
357 | return f[1](v[o[1]]), f[2](v[o[2]]) |
||
358 | end |
||
359 | end |
||
360 | elseif i == 3 then |
||
361 | return function(text) |
||
362 | _,_,v[1],v[2],v[3] = string.find(text, unpattern) |
||
363 | if v[1] then |
||
364 | return f[1](v[o[1]]), f[2](v[o[2]]), f[3](v[o[3]]) |
||
365 | end |
||
366 | end |
||
367 | elseif i == 4 then |
||
368 | return function(text) |
||
369 | _,_,v[1],v[2],v[3],v[4] = string.find(text, unpattern) |
||
370 | if v[1] then |
||
371 | return f[1](v[o[1]]), f[2](v[o[2]]), f[3](v[o[3]]), f[4](v[o[4]]) |
||
372 | end |
||
373 | end |
||
374 | elseif i == 5 then |
||
375 | return function(text) |
||
376 | _,_,v[1],v[2],v[3],v[4],v[5] = string.find(text, unpattern) |
||
377 | if v[1] then |
||
378 | return f[1](v[o[1]]), f[2](v[o[2]]), f[3](v[o[3]]), f[4](v[o[4]]), f[5](v[o[5]]) |
||
379 | end |
||
380 | end |
||
381 | elseif i == 6 then |
||
382 | return function(text) |
||
383 | _,_,v[1],v[2],v[3],v[4],v[5],v[6] = string.find(text, unpattern) |
||
384 | if v[1] then |
||
385 | return f[1](v[o[1]]), f[2](v[o[2]]), f[3](v[o[3]]), f[4](v[o[4]]), f[5](v[o[5]]), f[6](v[o[6]]) |
||
386 | end |
||
387 | end |
||
388 | elseif i == 7 then |
||
389 | return function(text) |
||
390 | _,_,v[1],v[2],v[3],v[4],v[5],v[6],v[7] = string.find(text, unpattern) |
||
391 | if v[1] then |
||
392 | return f[1](v[o[1]]), f[2](v[o[2]]), f[3](v[o[3]]), f[4](v[o[4]]), f[5](v[o[5]]), f[6](v[o[6]]), f[7](v[o[7]]) |
||
393 | end |
||
394 | end |
||
395 | elseif i == 8 then |
||
396 | return function(text) |
||
397 | _,_,v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8] = string.find(text, unpattern) |
||
398 | if v[1] then |
||
399 | return f[1](v[o[1]]), f[2](v[o[2]]), f[3](v[o[3]]), f[4](v[o[4]]), f[5](v[o[5]]), f[6](v[o[6]]), f[7](v[o[7]]), f[8](v[o[8]]) |
||
400 | end |
||
401 | end |
||
402 | else |
||
403 | return function(text) |
||
404 | _,_,v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9] = string.find(text, unpattern) |
||
405 | if v[1] then |
||
406 | return f[1](v[o[1]]), f[2](v[o[2]]), f[3](v[o[3]]), f[4](v[o[4]]), f[5](v[o[5]]), f[6](v[o[6]]), f[7](v[o[7]]), f[8](v[o[8]]), f[9](v[o[9]]) |
||
407 | end |
||
408 | end |
||
409 | end |
||
410 | end |
||
411 | end |
||
412 | |||
413 | function lib:Deformat(text, a1, a2, a3, a4) |
||
414 | local pattern = a1 |
||
415 | if a4 then |
||
416 | pattern = string.format("%s%s%s%s", a1, a2, a3, a4) |
||
417 | elseif a3 then |
||
418 | pattern = string.format("%s%s%s", a1, a2, a3) |
||
419 | elseif a2 then |
||
420 | pattern = a1 .. a2 |
||
421 | end |
||
422 | assert(pattern, "No pattern given") |
||
423 | if curries[pattern] == nil then |
||
424 | curries[pattern] = Curry(a1, a2, a3, a4) |
||
425 | end |
||
426 | return curries[pattern](text) |
||
427 | end |
||
428 | end |
||
429 | |||
430 | function lib:GetLibraryVersion() |
||
431 | return MAJOR_VERSION, MINOR_VERSION |
||
432 | end |
||
433 | |||
434 | function lib:LibActivate(stub, oldLib, oldList) |
||
435 | end |
||
436 | |||
437 | function lib:LibDeactivate() |
||
438 | end |
||
439 | |||
440 | BabbleLib:Register(lib) |
||
441 | lib = nil |