annotate LibKraken/LibStub/LibStub.lua @ 5:9ac29fe77455

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