WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Library version checking (https://www.wowinterface.com/forums/showthread.php?t=56180)

arith 04-25-18 09:11 PM

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.

AcidWeb 04-25-18 11:11 PM

Is LibUIDropDownMenu is needed anymore? If they fixed dropdown taint in 8.0 I don't see a reason to use it.

arith 04-26-18 12:40 AM

That's a good point, but I am not sure if they fix the dropdown taint.

Ellypse 04-26-18 01:19 AM

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 "AddonName@project-version@_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

arith 04-26-18 02:25 AM

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.

AcidWeb 04-27-18 01:09 PM

FYI is taint is still not fixed in 8.0.

https://www.townlong-yak.com/bugs/af...FrameLoadTaint

myrroddin 05-01-18 11:33 AM

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

p3lim 05-02-18 02:11 AM

Quote:

Originally Posted by myrroddin (Post 327847)
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).


All times are GMT -6. The time now is 04:28 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI