Quantcast
WoWInterface - View Single Post - Library version checking
View Single Post
05-01-18, 11:33 AM   #7
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,117
Late to the party, but a couple of quick notes. Neither of these are in the LibStub documentation.

This line:
Lua Code:
  1. local lib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
Is better written as:
Lua Code:
  1. local lib, oldminor = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
That way external version checks are more accurate when loading. Also, if an author ever needs to check for a specific minimum minor version or higher of a library, they can easily check against the minor because it is registered. LibStub will load the newest version regardless, but it will not necessarily store the minor in its tables unless expressly registered. Results may vary, of course.

The second thing several library authors forget is that all but three libraries should be loaded on demand. The exceptions being Ace3, LibStub, and CallbackHandler-1.0. For all other libraries, the following line in the .toc ought to be added. It certainly is not critical, but there is no point on loading a library if no addon actually uses it.
Lua Code:
  1. ## LoadOnDemand: 1
  Reply With Quote