12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appendix B ■ Utilizing Addon Libraries 1333or a lower minor version, the initialization process can safely returnimmediately.3. If a version exists but the minor version <strong>of</strong> the existing instance is lessthan the one being loaded, then this instance should replace (or upgrade)the existing instance with itself.4. If the major version does not already exist, the library should simply beloaded.Using embedded libraries, multiple copies <strong>of</strong> the library may be loaded <strong>and</strong>then thrown away, which can increase load times. This would only happen inthe situation where addons loaded in a specific order had increasing minorversions <strong>of</strong> the same library. In addition, the library author needs to be sensitiveto the potential upgrade process, <strong>and</strong> should test the library thoroughly be<strong>for</strong>ereleasing a minor version update to a library.Manually Versioning an Embedded LibraryThe code to manage the versioning <strong>of</strong> your library can be as simple as thefollowing:local minor_version = 501if MyLibraryName <strong>and</strong> minor_version < MyLibraryName.minor then-- This version is old, so don’t load itreturnend-- Library definition hereMyLibraryName = {}function MyLibraryName.createDebugFunc(prefix)return function(...)local succ, message = pcall(string.<strong>for</strong>mat, ...)if succ thenprint(“|cffff1100“ .. prefix .. “: |r“, message)elseprint(“|cffff1100“ .. prefix .. “: |r“, tostringall(...))endendendendIn this case the major version name is MyLibraryName, <strong>and</strong> the minor versionis 501. The code first checks to see if the major version exists <strong>and</strong>, if it does,compares the two minor versions. If the minor version being loaded is lessthan the one that already exists, the code returns.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!