flickerstreak@104: -- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info flickerstreak@104: -- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke flickerstreak@104: local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS! flickerstreak@104: local LibStub = _G[LIBSTUB_MAJOR] flickerstreak@104: flickerstreak@104: if not LibStub or LibStub.minor < LIBSTUB_MINOR then flickerstreak@104: LibStub = LibStub or {libs = {}, minors = {} } flickerstreak@104: _G[LIBSTUB_MAJOR] = LibStub flickerstreak@104: LibStub.minor = LIBSTUB_MINOR flickerstreak@104: flickerstreak@104: function LibStub:NewLibrary(major, minor) flickerstreak@104: assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)") flickerstreak@104: minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.") flickerstreak@104: flickerstreak@104: local oldminor = self.minors[major] flickerstreak@104: if oldminor and oldminor >= minor then return nil end flickerstreak@104: self.minors[major], self.libs[major] = minor, self.libs[major] or {} flickerstreak@104: return self.libs[major], oldminor flickerstreak@104: end flickerstreak@104: flickerstreak@104: function LibStub:GetLibrary(major, silent) flickerstreak@104: if not self.libs[major] and not silent then flickerstreak@104: error(("Cannot find a library instance of %q."):format(tostring(major)), 2) flickerstreak@104: end flickerstreak@104: return self.libs[major], self.minors[major] flickerstreak@104: end flickerstreak@104: flickerstreak@104: function LibStub:IterateLibraries() return pairs(self.libs) end flickerstreak@104: setmetatable(LibStub, { __call = LibStub.GetLibrary }) flickerstreak@104: end