annotate lib/LibStub/LibStub.lua @ 28:21bcaf8215ff

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