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