Skip to content

Repository files navigation

LibStub

LibStub is a simple versioning stub meant for use in Libraries.

Download

-- download from subversionsvncheckouthttps://repos.curseforge.com/wow/libstub/trunk .

Examples

Basic example

locallib=LibStub:NewLibrary("MyLibrary-1.0", 1)
ifnotlibthenreturn-- already loaded and no upgrade necessaryendlib.somearray=lib.somearrayor {}
ifnotlib.framethenlib.frame=CreateFrame("Frame")
endfunctionlib:SomeFunction()
-- do stuff hereendfunctionlib:SomeOtherFunction()
-- do other stuff hereendlocalfunctionOnUpdate()
-- timing stuff hereendlib.frame:SetScript("OnUpdate", OnUpdate);

Using revision control system tags for minor version

locallib=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:

locallib=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.mixinTargetsor {}
localmixins= {"SomeFunction", "SomeOtherFunction" }
functionlib:Embed(target)
for_,nameinpairs(mixins) dotarget[name] =lib[name]
endlib.mixinTargets[target] =trueend

... 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:

fortarget,_inpairs(mixinTargets) dolib:Embed(target)
end

About

LibStub is a simple versioning stub meant for use in Libraries.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages