ESOUI SVN ZAMBuffDisplay

[/] [libs/] [LibStub/] [LibStub.lua] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Seerah-7
-- LibStub is a simple versioning stub meant for use in Libraries.  http://www.wowace.com/wiki/LibStub for more info
2 Seerah-7
-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
3 Seerah-7
-- LibStub developed for World of Warcraft by above members of the WowAce community.
4 Seerah-7
-- Ported to Elder Scrolls Online by Seerah
5 Seerah-7
 
6 Seerah-7
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 1  -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
7 Seerah-7
local LibStub = _G[LIBSTUB_MAJOR]
8 Seerah-7
 
9 Seerah-7
local strformat = string.format
10 Seerah-7
if not LibStub or LibStub.minor < LIBSTUB_MINOR then
11 Seerah-7
        LibStub = LibStub or {libs = {}, minors = {} }
12 Seerah-7
        _G[LIBSTUB_MAJOR] = LibStub
13 Seerah-7
        LibStub.minor = LIBSTUB_MINOR
14 Seerah-7
 
15 Seerah-7
        function LibStub:NewLibrary(major, minor)
16 Seerah-7
                assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
17 Seerah-7
                minor = assert(tonumber(zo_strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
18 Seerah-7
 
19 Seerah-7
                local oldminor = self.minors[major]
20 Seerah-7
                if oldminor and oldminor >= minor then return nil end
21 Seerah-7
                self.minors[major], self.libs[major] = minor, self.libs[major] or {}
22 Seerah-7
                return self.libs[major], oldminor
23 Seerah-7
        end
24 Seerah-7
 
25 Seerah-7
        function LibStub:GetLibrary(major, silent)
26 Seerah-7
                if not self.libs[major] and not silent then
27 Seerah-7
                        error(("Cannot find a library instance of %q."):strformat(tostring(major)), 2)
28 Seerah-7
                end
29 Seerah-7
                return self.libs[major], self.minors[major]
30 Seerah-7
        end
31 Seerah-7
 
32 Seerah-7
        function LibStub:IterateLibraries() return pairs(self.libs) end
33 Seerah-7
        setmetatable(LibStub, { __call = LibStub.GetLibrary })
34 Seerah-7
end