Mercurial > wow > itemauditor
comparison Libs/LibStub/LibStub.lua @ 0:169f5211fc7f
First public revision.
At this point ItemAuditor watches mail for auctions sold or purchased, watches for buy/sell (money and 1 item type change) and conversions/tradeskills. Milling isn't working yet because there is too much time between the first event and the last event.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Thu, 20 May 2010 19:22:19 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:169f5211fc7f |
---|---|
1 -- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info | |
2 -- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke | |
3 local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS! | |
4 local LibStub = _G[LIBSTUB_MAJOR] | |
5 | |
6 if not LibStub or LibStub.minor < LIBSTUB_MINOR then | |
7 LibStub = LibStub or {libs = {}, minors = {} } | |
8 _G[LIBSTUB_MAJOR] = LibStub | |
9 LibStub.minor = LIBSTUB_MINOR | |
10 | |
11 function LibStub:NewLibrary(major, minor) | |
12 assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)") | |
13 minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.") | |
14 | |
15 local oldminor = self.minors[major] | |
16 if oldminor and oldminor >= minor then return nil end | |
17 self.minors[major], self.libs[major] = minor, self.libs[major] or {} | |
18 return self.libs[major], oldminor | |
19 end | |
20 | |
21 function LibStub:GetLibrary(major, silent) | |
22 if not self.libs[major] and not silent then | |
23 error(("Cannot find a library instance of %q."):format(tostring(major)), 2) | |
24 end | |
25 return self.libs[major], self.minors[major] | |
26 end | |
27 | |
28 function LibStub:IterateLibraries() return pairs(self.libs) end | |
29 setmetatable(LibStub, { __call = LibStub.GetLibrary }) | |
30 end |