WoW LibStub addon Dragonflight/Wrath of the Lich King Classic 2024
logo
wow addon LibStub

LibStub

Game Version: 7.0.3
Total Downloads: 1,244,823
Updated: Aug 18, 2016
Created: Apr 14, 2008
download LibStubDownload Earlier Versions

Earlier Versions

Name Size Uploaded Game Version Downloads
1.0.2-70000 release 3.94 KB Aug 18, 2016 7.0.3 226,164 download LibStub 1.0.2-70000 releaseDownload
1.0.2.60000 release 3.98 KB Oct 16, 2014 6.0.2 132,039 download LibStub 1.0.2.60000 releaseDownload
1.0.2 release 3.92 KB Jul 24, 2011 4.2.0 399,379 download LibStub 1.0.2 releaseDownload
1.0.1 release 4.03 KB Jan 14, 2011 4.0.3a 266,114 download LibStub 1.0.1 releaseDownload
1.0 release 1.38 KB Sep 30, 2008 3.0.2 212,754 download LibStub 1.0 releaseDownload
LibStub-r47506 beta 17.76 KB Aug 27, 2007 2.1.3 1,368 download LibStub LibStub-r47506 betaDownload
LibStub-r47505 beta 16.97 KB Aug 27, 2007 2.1.3 636 download LibStub LibStub-r47505 betaDownload
LibStub-r47500 beta 14.77 KB Aug 27, 2007 2.1.3 540 download LibStub LibStub-r47500 betaDownload
LibStub-r47490 beta 13.96 KB Aug 27, 2007 2.1.3 186 download LibStub LibStub-r47490 betaDownload
LibStub-r47489 beta 13.74 KB Aug 27, 2007 2.1.3 166 download LibStub LibStub-r47489 betaDownload
LibStub-r47487 beta 13.43 KB Aug 27, 2007 2.1.3 153 download LibStub LibStub-r47487 betaDownload
LibStub-r47478 beta 13.14 KB Aug 26, 2007 2.1.3 196 download LibStub LibStub-r47478 betaDownload
LibStub-r47477 beta 12.79 KB Aug 26, 2007 2.1.3 144 download LibStub LibStub-r47477 betaDownload
LibStub-r47467 beta 12.54 KB Aug 26, 2007 2.1.3 157 download LibStub LibStub-r47467 betaDownload
LibStub-r47465 beta 12.03 KB Aug 26, 2007 2.1.3 162 download LibStub LibStub-r47465 betaDownload
LibStub-r47446 beta 11.75 KB Aug 26, 2007 2.1.3 135 download LibStub LibStub-r47446 betaDownload
LibStub-r47441 beta 11.26 KB Aug 26, 2007 2.1.3 186 download LibStub LibStub-r47441 betaDownload
LibStub-r47439 beta 10.97 KB Aug 26, 2007 2.1.3 142 download LibStub LibStub-r47439 betaDownload
LibStub-r47436 beta 10.25 KB Aug 26, 2007 2.1.3 203 download LibStub LibStub-r47436 betaDownload
LibStub-r47433 beta 10.25 KB Aug 26, 2007 2.1.3 180 download LibStub LibStub-r47433 betaDownload
LibStub-r47429 beta 10.05 KB Aug 26, 2007 2.1.3 143 download LibStub LibStub-r47429 betaDownload
LibStub-r47426 beta 9.75 KB Aug 26, 2007 2.1.3 180 download LibStub LibStub-r47426 betaDownload
LibStub-r47394 beta 9.40 KB Aug 25, 2007 2.1.3 146 download LibStub LibStub-r47394 betaDownload
LibStub-r47366 beta 9.14 KB Aug 24, 2007 2.1.3 155 download LibStub LibStub-r47366 betaDownload
LibStub-r47364 beta 8.66 KB Aug 24, 2007 2.1.3 106 download LibStub LibStub-r47364 betaDownload
LibStub-r47361 beta 8.46 KB Aug 24, 2007 2.1.3 105 download LibStub LibStub-r47361 betaDownload
LibStub-r47360 beta 8.46 KB Aug 24, 2007 2.1.3 90 download LibStub LibStub-r47360 betaDownload
LibStub-r47348 beta 8.16 KB Aug 24, 2007 2.1.3 117 download LibStub LibStub-r47348 betaDownload
LibStub-r47347 beta 7.95 KB Aug 24, 2007 2.1.3 236 download LibStub LibStub-r47347 betaDownload
LibStub-r47341 beta 7.77 KB Aug 24, 2007 2.1.3 99 download LibStub LibStub-r47341 betaDownload
LibStub-r47336 beta 7.47 KB Aug 24, 2007 2.1.3 86 download LibStub LibStub-r47336 betaDownload
LibStub-r47335 beta 7.08 KB Aug 24, 2007 2.1.3 153 download LibStub LibStub-r47335 betaDownload
LibStub-r47332 beta 6.84 KB Aug 24, 2007 2.1.3 133 download LibStub LibStub-r47332 betaDownload
LibStub-r47325 beta 5.03 KB Aug 24, 2007 2.1.3 94 download LibStub LibStub-r47325 betaDownload
LibStub-r47324 beta 4.45 KB Aug 24, 2007 2.1.3 139 download LibStub LibStub-r47324 betaDownload
LibStub-r47319 beta 4.17 KB Aug 24, 2007 2.1.3 153 download LibStub LibStub-r47319 betaDownload
LibStub-r47317 beta 3.64 KB Aug 24, 2007 2.1.3 97 download LibStub LibStub-r47317 betaDownload
LibStub-r47315 beta 3.24 KB Aug 24, 2007 2.1.3 93 download LibStub LibStub-r47315 betaDownload
LibStub-r47311 beta 2.23 KB Aug 24, 2007 2.1.3 104 download LibStub LibStub-r47311 betaDownload
LibStub-r47310 beta 1.86 KB Aug 24, 2007 2.1.3 105 download LibStub LibStub-r47310 betaDownload
LibStub-r47291 beta 1.53 KB Aug 24, 2007 2.1.3 101 download LibStub LibStub-r47291 betaDownload
LibStub-r47287 beta 948 Bytes Aug 23, 2007 2.1.3 197 download LibStub LibStub-r47287 betaDownload
r89 alpha 1.81 KB Sep 30, 2008 2.4.3 987 download LibStub r89 alphaDownload

Description

Share this:

LibStub is a minimalistic versioning library that allows other libraries to easily register themselves and upgrade. It is meant to be a cross-community library sharing system.
LibStub is hereby placed in the Public Domain
Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke

LibStub-1.0 API

:GetLibrary(major [, silent])

Returns

The table instance of a registered library or nil if not found and the minor version of the library as the second return value.

Arguments

major
The name of the library you are requesting
silent
(Optional) Suppresses errors when the library is not found

:IterateLibraries()

Returns

An iterator over the registered major libraries.

:NewLibrary(major , minor)

Returns

The table to be used by the library as well as the minor version of the previously registered library, if any.

Arguments

major
The name of the library you are requesting
minor
The minor for the registering library

Who uses LibStub?

  • Ace3, for which it was originally designed
  • Rock, ckknight's framework
  • Norganna has announced that the next major version of Auctioneer will use it for its libraries
  • Some Dongle-related libraries use it.
  • … and hopefully many more to come!

How to include LibStub in a library or addon

Library

if using the WoWAce repositories

  • setup an external pointing to <tt>svn://svn.wowace.com/wow/libstub/mainline/trunk</tt> in the .pkgmeta file
  • disable nolib creation by adding <tt>enable-nolib-creation: no</tt> to the .pkgmeta file
  • set up your <library>.toc file to load LibStub.lua (in case you support stand alone loading of the lib)
  • don't load LibStub via the xml file ment for embedded loading of your lib
  • don't set LibStub as X-embeded or OptDep

otherwise

  • get a copy of the current version
  • copy LibStub.lua into your library's folder
  • set up your <library>.toc file to load LibStub.lua (in case you support stand alone loading of the lib)
  • don't load LibStub via the xml file ment for embedded loading of your lib
  • don't set LibStub as X-embeded or OptDep

AddOn

if using the WoWAce repositories

  • set up an external pointing to <tt>svn://svn.wowace.com/wow/libstub/mainline/trunk</tt> in the .pkgmeta file
  • set up your <addon>.toc or embeds.xml file to load LibStub.lua
  • don't set LibStub as X-embeded or OptDep

otherwise

  • get a copy of the current version
  • copy LibStub.lua into your addon's folder or a subfolder of it
  • set up your <addon>.toc or embeds.xml file to load LibStub.lua
  • don't set LibStub as X-embeded or OptDep

Examples

Basic example

local lib = LibStub:NewLibrary("MyLibrary-1.0", 1)

if not lib then
  return	-- already loaded and no upgrade necessary
end

lib.somearray = lib.somearray or {}

if not lib.frame then
  lib.frame=CreateFrame("Frame")
end


function lib:SomeFunction()
  -- do stuff here
end

function lib:SomeOtherFunction()
  -- do other stuff here
end

local function OnUpdate()
  -- timing stuff here
end

lib.frame:SetScript("OnUpdate", OnUpdate);

Using revision control system tags for minor version

local lib = LibStub:NewLibrary("MyLibrary-1.0", "$Revision: 12345$")

Do be aware that moving a library from one repository to another will change revision numbers. Do not ever let it slide backwards. If you are caught in this situation, you might want to use something like:

local lib = LibStub:NewLibrary("MyLibrary-1.0", 
  12345+tonumber(strmatch("%d+","$Revision: 2$")) 
)

Embedding / Mixing in

This is a convention rather than a function of the specification, but all Ace3 and Rock related libraries use the following semantics for doing embedding / mixing in (specifically, libraries with an .Embed() member can be specified as embeds during addon object creation rather than having to embed them explicitly):

lib.mixinTargets = lib.mixinTargets or {}
local mixins = {"SomeFunction", "SomeOtherFunction" }

function lib:Embed(target)
  for _,name in pairs(mixins) do
    target[name] = lib[name]
  end
  lib.mixinTargets[target] = true
end

… and at the end of the file, we handle library upgrades by simply re-embedding the library in all positions where it has previously been embedded / mixed in:

for target,_ in pairs(mixinTargets) do
  lib:Embed(target)
end

Comments

Add a comment