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