Thread Tools Display Modes
05/16/14, 02:42 PM   #1
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 655
LibStub and Libraries loading First

Without LibStub

So I have been investigating why when there are three mods all using CustomCompassPins that they only work when all three mods are using the same file. What I am learning from Shinni is that one of the three libraries is going to load first. So take this scenario. I have 1.14, 1.17, and 1.19 in the three mods. If 1.17 load first then it defines the routines. When 1.19 loads it redefines, updates, or changes the functions. There is a routine to check for the version number that does not use LibStub and when 1.14 loads last it won't load at all because 1.17 and 1.19 are newer versions.

With LibStub

1.17 still loads before 1.19, then 1.19 loads and then 1.14 does not load.

Question:

Lua Code:
  1. local MAJOR, MINOR = "CustomCompassPins-1.0", 4
  2. local CustomCompassPins, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
  3. if not CustomCompassPins then return end    --the same or newer version of this lib is already loaded into memory
So when I have a ,4 ,7 and ,9 doesn't that make 9 the newest file?

When using that syntax why wouldn't it say I have three known versions of the same library so I am only going to load the newest one. Stopping 1.14 and 1.17 from loading at all even if they tried to load before 1.19. Can LibStub do that? Can LibStub catalog all the versions of the libraries prior to loading them and then decide which one to use?
  Reply With Quote
05/16/14, 03:18 PM   #2
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
LibStub doesn't do a delayed load (which could cause other issues). It doesn't know what the later addons will have when it initializes the library, so it goes with the current highest. That means if the newer version comes later in the load order, it will be loaded as well.

Example, you have AddonA with 1.17, AddonB with 1.14, and AddonC with 1.19

If it goes through AddonA, AddonB, AddonC for load order:
AddonA - first addon, loads 1.17 of the lib.
AddonB - already loaded 1.17 which is newer than 1.14. Do nothing
AddonC - 1.19 is newer, load version 1.19 of the lib

In order for LibStub to behave as you described, it would have to wait until all the addons are loaded before it initializes the libraries. Of course, this means the Addon init functions would have to be pushed back as well.

What are you running into with loading the library twice?
  Reply With Quote
05/16/14, 03:45 PM   #3
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 655
Originally Posted by Sasky View Post
LibStub doesn't do a delayed load (which could cause other issues). It doesn't know what the later addons will have when it initializes the library, so it goes with the current highest. That means if the newer version comes later in the load order, it will be loaded as well.

Example, you have AddonA with 1.17, AddonB with 1.14, and AddonC with 1.19

If it goes through AddonA, AddonB, AddonC for load order:
AddonA - first addon, loads 1.17 of the lib.
AddonB - already loaded 1.17 which is newer than 1.14. Do nothing
AddonC - 1.19 is newer, load version 1.19 of the lib

In order for LibStub to behave as you described, it would have to wait until all the addons are loaded before it initializes the libraries. Of course, this means the Addon init functions would have to be pushed back as well.

What are you running into with loading the library twice?
I have been testing why there are no map and compass pins when multiple mods use the same version of the library.

However, as we speak it's working fine. I am totally confused as to why though because at least two people reported in the past they could not see pins. The fix was that all the versions had to have the same library. I had it happen to me this morning and I started looking for a reason. I kept backups of everything. Now no matter which backup I restore, everything works fine. I see map and compass pins. I'm totally confused now. Since it's working I'll just move on unless it quits working again in the future.
  Reply With Quote
05/16/14, 08:27 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Perhaps there was a change in a newer version of the library that was not backwards compatible and the other addons needed to update. When making changes in a library, it is important to keep compatibility. Otherwise, it breaks other addons that use the library.
  Reply With Quote
05/16/14, 10:33 PM   #5
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Seerah View Post
Perhaps there was a change in a newer version of the library that was not backwards compatible and the other addons needed to update. When making changes in a library, it is important to keep compatibility. Otherwise, it breaks other addons that use the library.
There was no such change in CustomCompassPins library, versions 1.11 and later are compatible.
The only incompatible version was 1.1 used by old EsoheadMarkers (before addon was renamed to HarvestMap) - it did not have update function yet.

Last edited by Garkin : 05/16/14 at 10:41 PM.
  Reply With Quote
05/18/14, 11:09 AM   #6
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
I wrote a short intro into what LibStub does (and what would happen without) over in the Addon forum at eso:
libStub:
http://www.esoui.com/downloads/info44-LibStub.html
You can easily have multiple instances and even version of the same library in your addon folder. Not only bring several addons them along, you might have a standalone copy. In this case wichever version is last executed would be the one used (as all addons access the same global variables for exposure, so it's "last come last served"). Unless the Library uses libStub. It's a library with the sole purpose of being a library version tool.
Using the libStub block other libraries .lua file will first check if a newer or the same version has already been loaded/executed. If that is the case, the .lua file is just skipped (via an early return).
If not (no or older version) the .lua file is executed. This makes certain that only the most recent version is in memory and that if a dozen addons bring the same version along only one of them is executed.
For optimal result also add the libraries to your "OptionalDependsOn". If the user has a standalone version installed that one is much more likely to be up to date. While it would still end up "on top" eventually, the lesser versions might still be executed costing unessesary time.
libStub uses two values to identify a library: The major and minor. It they have different major values, they are different libraries. If they have different minors, they are just different versions of the same library. You only change the major if something changed with the exposed functions (like names or wich functions are provided) or if otherwise backwards compatibility is not certain.
Since the 1.1 version lacked the LibStub block and ESOHEAD brought a 1.1 Version along, the (outdated) 1.1 would overwrite all the nice 1.11 isntalled (if it happened to run last).
The only certainty you have about excution order is that the order in your manifest is followed and that dependencies run before the addons that depends on them.
  Reply With Quote
05/18/14, 02:49 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Here is another thread on LibStub: http://www.esoui.com/forums/showthre...hlight=libstub
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » LibStub and Libraries loading First


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