Advertisement
draugath

VOLibStub

Mar 9th, 2012
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  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.  
  4. -- LibStub for Vendetta Online was forked from LibStub minor version 2, due to differences in the API
  5. -- LibStub fork for Vendetta Online: draugath
  6.  
  7.  
  8. local LIBSTUB_MAJOR, LIBSTUB_MINOR = "VOLibStub", 1  -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
  9. local LibStub = loadstring('return '..LIBSTUB_MAJOR)()
  10.  
  11. if not LibStub or LibStub.minor < LIBSTUB_MINOR then
  12.     LibStub = LibStub or {libs = {}, minors = {} }
  13.     declare(LIBSTUB_MAJOR, LibStub)
  14.     LibStub.minor = LIBSTUB_MINOR
  15.    
  16.     function LibStub:NewLibrary(major, minor)
  17.         assert(type(major) == "string", "Bad argument #2 to 'NewLibrary' (string expected, got "..type(major)..")")
  18.         assert(type(minor) == "number" or
  19.                type(minor) == "string", "Bad argument #3 to 'NewLibrary' (number or string expected, got "..type(minor)..")")
  20.         minor = assert(tonumber(string.match(minor, "%d+")), "Minor version must either be a number or contain a number.")
  21.        
  22.         local oldminor = self.minors[major]
  23.         if oldminor and oldminor >= minor then return nil end
  24.         self.minors[major], self.libs[major] = minor, self.libs[major] or {}
  25.         return self.libs[major], oldminor
  26.     end
  27.    
  28.     function LibStub:GetLibrary(major, silent)
  29.         if not self.libs[major] and not silent then
  30.             error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
  31.         end
  32.         return self.libs[major], self.minors[major]
  33.     end
  34.    
  35.     function LibStub:IterateLibraries() return pairs(self.libs) end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement