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