vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 ---------------------------------------------------------------------------
2 -- Embedded Library Registration Stub
3 --
4 -- Written by Iriel <iriel@vigilance-committee.org>
5 --
6 -- Version 0.1 - 2006-03-05
7 ---------------------------------------------------------------------------
8 -- To use this for your own AddOns, copy this file and then edit only the
9 -- section at the bottom with the appropriate library name(s).
10 ---------------------------------------------------------------------------
11 local stub = {};
12  
13 -- Instance replacement method, replace contents of old with that of new
14 function stub:ReplaceInstance(old, new)
15 for k,v in pairs(old) do old[k]=nil; end
16 for k,v in pairs(new) do old[k]=v; end
17 end
18  
19 -- Get a new copy of the stub
20 function stub:NewStub()
21 local newStub = {};
22 self:ReplaceInstance(newStub, self);
23 newStub.lastVersion = '';
24 newStub.versions = {};
25 return newStub;
26 end
27  
28 -- Get instance version
29 function stub:GetInstance(version)
30 if (not version) then version = self.lastVersion; end
31 local versionData = self.versions[version];
32 if (not versionData) then
33 message("Cannot find library instance with version '"
34 .. version .. "'");
35 return;
36 end
37 return versionData.instance;
38 end
39  
40 -- Register new instance
41 function stub:Register(newInstance)
42 local version,minor = newInstance:GetLibraryVersion();
43 self.lastVersion = version;
44 local versionData = self.versions[version];
45 if (not versionData) then
46 -- This one is new!
47 versionData = { instance = newInstance,
48 minor = minor,
49 old = {}
50 };
51 self.versions[version] = versionData;
52 newInstance:LibActivate(self);
53 return newInstance;
54 end
55 if (minor <= versionData.minor) then
56 -- This one is already obsolete
57 if (newInstance.LibDiscard) then
58 newInstance:LibDiscard();
59 end
60 return versionData.instance;
61 end
62 -- This is an update
63 local oldInstance = versionData.instance;
64 local oldList = versionData.old;
65 versionData.instance = newInstance;
66 versionData.minor = minor;
67 local skipCopy = newInstance:LibActivate(self, oldInstance, oldList);
68 table.insert(oldList, oldInstance);
69 if (not skipCopy) then
70 for i, old in ipairs(oldList) do
71 self:ReplaceInstance(old, newInstance);
72 end
73 end
74 return newInstance;
75 end
76  
77 ----------------------------------------------------------------------------
78 -- PUT LIBRARY INSTANCES HERE
79 --
80 -- if (not LibName) then LibName = stub:NewStub(); end
81 -- Follow all with stub = nil
82  
83 -- Set up IrielVirtualFrames (IrielPrototype-2-dev/617)
84 if (not IrielVirtualFrames) then IrielVirtualFrames = stub:NewStub(); end
85  
86 -- Release stub to gc
87 stub = nil;