annotate 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
rev   line source
Asa@0 1 -- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info
Asa@0 2 -- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
Asa@0 3 local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
Asa@0 4 local LibStub = _G[LIBSTUB_MAJOR]
Asa@0 5
Asa@0 6 if not LibStub or LibStub.minor < LIBSTUB_MINOR then
Asa@0 7 LibStub = LibStub or {libs = {}, minors = {} }
Asa@0 8 _G[LIBSTUB_MAJOR] = LibStub
Asa@0 9 LibStub.minor = LIBSTUB_MINOR
Asa@0 10
Asa@0 11 function LibStub:NewLibrary(major, minor)
Asa@0 12 assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
Asa@0 13 minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
Asa@0 14
Asa@0 15 local oldminor = self.minors[major]
Asa@0 16 if oldminor and oldminor >= minor then return nil end
Asa@0 17 self.minors[major], self.libs[major] = minor, self.libs[major] or {}
Asa@0 18 return self.libs[major], oldminor
Asa@0 19 end
Asa@0 20
Asa@0 21 function LibStub:GetLibrary(major, silent)
Asa@0 22 if not self.libs[major] and not silent then
Asa@0 23 error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
Asa@0 24 end
Asa@0 25 return self.libs[major], self.minors[major]
Asa@0 26 end
Asa@0 27
Asa@0 28 function LibStub:IterateLibraries() return pairs(self.libs) end
Asa@0 29 setmetatable(LibStub, { __call = LibStub.GetLibrary })
Asa@0 30 end