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