Quantcast Library version checking - WoWInterface
Thread Tools Display Modes
04-25-18, 09:11 PM   #1
arith
A Cyclonian
 
arith's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 41
Library version checking

I was reviewing the LibUIDropDown codes and then realized I made a mistake by putting version revision in the MAJOR_VERSION, which will result in multiple version of libs get loaded and some functions could be conflicted.
Before:
Lua Code:
  1. local MAJOR_VERSION = "LibUIDropDownMenu-1.07.7030024931"
  2. local MINOR_VERSION = 90000 + tonumber(("$Rev: 25 $"):match("%d+"))
  3.  
  4. local LibStub = _G.LibStub
  5. if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end
  6. local lib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
  7. if not lib then return end

Now I have fixed it to below:
Lua Code:
  1. local MAJOR_VERSION = "LibUIDropDownMenu"
  2. local MINOR_VERSION = 90000 + tonumber(("$Rev: 30 $"):match("%d+"))
  3.  
  4. local LibStub = _G.LibStub
  5. if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end
  6. local lib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
  7. if not lib then return end

But I am wondering how to do similar version checking in XML files?
The LibUIDropDownMenu has two XML files, and while synchronizing the changes in WoW 8.0.1, there are several changes need to be implemented in those XML files. So question pops up.

Instead of moving all those XML UI to be handled in Lua, I wonder if there is some easy way to do it within XML file.
  Reply With Quote
04-25-18, 11:11 PM   #2
AcidWeb
A Theradrim Guardian
 
AcidWeb's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 64
Is LibUIDropDownMenu is needed anymore? If they fixed dropdown taint in 8.0 I don't see a reason to use it.
  Reply With Quote
04-26-18, 12:40 AM   #3
arith
A Cyclonian
 
arith's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 41
That's a good point, but I am not sure if they fix the dropdown taint.
  Reply With Quote
04-26-18, 01:19 AM   #4
Ellypse
Storyline and TRP dev.
 
Ellypse's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 9
They have added new XML templates and Lua mixins for the dropdown menus, but I have not been able to test if using those new templates avoid the taint yet.

As for your original question, I have had the same issue with a custom lib I'm doing to share between my projects and I have not been able to find a solution either. One thing I had in mind at some point was that if you are using a packager for your add-on you are able to insert tags that would be automatically replaced by the version number. I was thinking that having XML names as "[email protected]@_WidgetName" would make different names for different versions of the lib. But I have not tried that yet and it sounds like a hacky solution :S
  Reply With Quote
04-26-18, 02:25 AM   #5
arith
A Cyclonian
 
arith's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 41
For UIDropDown, the new stuff is related to Custom Frame. Comments from UIDropDownMenuTemplates.lua:
Lua Code:
  1. -- Custom dropdown buttons are instantiated by some external system.
  2. -- When calling L_UIDropDownMenu_AddButton that system sets info.customFrame to the instance of the frame it wants to place on the menu.
  3. -- The dropdown menu creates its button for the entry as it normally would, but hides all elements.  The custom frame is then anchored
  4. -- to that button and assumes responsibility for all relevant dropdown menu operations.
  5. -- The hidden button will request a size that it should become from the custom frame.

Regarding to the possible workaround mentioned by Ellypse, I think technically it may work. But this would also introduce some problem for other addon's developer when then need to use those UI element.
  Reply With Quote
04-27-18, 01:09 PM   #6
AcidWeb
A Theradrim Guardian
 
AcidWeb's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 64
FYI is taint is still not fixed in 8.0.

https://www.townlong-yak.com/bugs/af...FrameLoadTaint
  Reply With Quote
05-01-18, 11:33 AM   #7
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 912
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
05-02-18, 02:11 AM   #8
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,665
Originally Posted by myrroddin View Post
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
This will require every addon that uses the library to handle loading it properly. LoD is not a magic flag that doesn't load the addon unless it's a dependency, it must be manually loaded by another addon to work (which will introduce hiccups for the player as the addon loads, depending on the size of the library).
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Library version checking

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off