annotate Libs/LibStub/LibStub.lua @ 28:7523376ecaa3

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