Quantcast
Download
(2 Kb)
Download
Updated: 02/24/20 02:38 AM
Compatibility:
Harrowstorm (5.3.4)
Dragonhold (5.2.5)
Scalebreaker (5.1.5)
Elsweyr (5.0.5)
Updated:02/24/20 02:38 AM
Created:03/02/14 04:10 PM
Monthly downloads:107,944
Total downloads:682,567
Favorites:756
MD5:
5.3.4
LibStub  Updated this week!  Popular! (More than 5000 hits)
Version: 1.0 r7
by: sirinsidiator, Seerah

LibStub was replaced by features in the game and won't be updated anymore!
If you are using an addon which still relies on LibStub, either ask the author to remove it or you just need to live with it.



Addon Authors: LibStub is no longer needed if you plan to write a new library.
The game can manage the versioning itself, so just write your library like you would any other addon and make sure you add the "IsLibrary" and "AddOnVersion" directive.
Code:
## AddOnVersion: 6
## IsLibrary: true
Check the wiki for more more details about the directives.

In order to encourage moving away from LibStub, starting with r7 it will print a deprecation warning in chat in case any of the installed addons uses LibStub to reference a library. This message can be disabled with "/libstubwarning off". Authors can install LibDebugLogger and the DebugLogViewer in order to see where offending calls to LibStub come from. Simply enable stack trace logging via "/debuglogger stack on", reload the UI and click on the warnings in the log.


LibStub was written for World of Warcraft by Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel and joshborke. It was ported to Elder Scrolls Online by Seerah. The below description was copied from WowAce with a few minor revisions.


LibStub is a minimalistic versioning library that allows other libraries to easily register themselves and upgrade. It is meant to be a cross-community library sharing system.

LibStub is hereby placed in the Public Domain


LibStub-1.0 API

:GetLibrary(major [, silent])
Returns
The table instance of a registered library or nil if not found and the minor version of the library as the second return value.
Arguments
major
The name of the library you are requesting
silent
(Optional) Suppresses errors when the library is not found. You can pass LibStub.SILENT for better readability
:IterateLibraries()
Returns
An iterator over the registered major libraries.
:NewLibrary(major , minor)
Returns
The table to be used by the library as well as the minor version of the previously registered library, if any.
Arguments
major
The name of the library you are requesting
minor
The minor for the registering library

Who uses LibStub?
LibAddonMenu-1.0
... and hopefully many more to come!

How to include LibStub in a library or addon

Library
  • get a copy of the current version
  • copy LibStub.lua into your library's folder
  • set up your <library>.txt file to load LibStub.lua (in case your library supports being installed standalone)
  • don't set LibStub as OptionalDependsOn

AddOn
  • get a copy of the current version
  • copy LibStub.lua into your addon's folder or a subfolder of it
  • set up your <addon>.txt file to load LibStub.lua
  • don't set LibStub as OptionalDependsOn


Basic Example

Lua Code:
  1. local lib = LibStub:NewLibrary("MyLibrary-1.0", 1)
  2.  
  3. if not lib then
  4.   return    -- already loaded and no upgrade necessary
  5. end
  6.  
  7. function lib:SomeFunction()
  8.   -- do stuff here
  9. end
  10.  
  11. function lib:SomeOtherFunction()
  12.   -- do other stuff here
  13. end
1.0 r7
- added deprecation chat warning
- added LibDebugLogger support
- api bump

1.0 r6
- added IsLibrary flag to manifest
- api bump (see below)

1.0 r5
- api bump (for all the poor people who don't like to check a checkbox)

1.0 r4
- added a named constant for the silent flag as proposed by merlight

1.0 r3
- added support for fractional numbers in minor library version as proposed by merlight

1.0 r2
- fixed error handling

1.0 r1
- updated version number in LibStub.txt to match internal Major, minor revisions (1.0 r1 instead of 1.0.1)
Archived Files (7)
File Name
Version
Size
Uploader
Date
1.0 r6
1kB
sirinsidiator
05/21/19 03:03 PM
1.0 r5
1kB
sirinsidiator
11/02/18 08:08 AM
1.0 r4
1kB
sirinsidiator
07/23/15 02:57 PM
1.0 r3
1kB
sirinsidiator
06/14/15 12:55 PM
1.0 r2
2kB
Seerah
07/13/14 09:24 PM
1.0 r1
2kB
Seerah
03/14/14 07:29 PM
1.0.1
2kB
Seerah
03/02/14 04:10 PM


Post A Reply Comment Options
Unread 02/25/20, 12:31 PM  
desertforce

Forum posts: 3
File comments: 76
Uploads: 0
Thanks for the answer ...

I will try it out on the addon *AutoInvite*... That still uses - at least the version I have - LibStub... As far as I can tell there is only the LibStub folder in the addon and the *Code-Line* (lib/LibStub/LibStub.lua) in the AutoInvite.txt file... I will remove that line, replace it with the global code - as mentioned on the mainpage here - and then I will delete the LibStub folder from it and see what will happen ...


Best regards
De-chan


Originally Posted by sirinsidiator
Originally Posted by desertforce
Hi... I've got a question...

For removing the LibStub:

For an Addon to keep working, will it be only necessary to change the entries within the *.txt manifest before removing the "Libstub" folder from the addon or will it be necessary to change more..?

Just asking because if only the *.txt manifest needs to be changed I could do it myself without the need to wait for an update from the author ... But if it would take more, then I would need to wait for updates or try to look for new/other addons to replace some older ones ...

Best regards
De-chan
Removing LibStub will require changes to the addon code. In most cases it should be as simple as finding the line where LibStub is called (as explained in the LibStub addon description) and replace it with the global variable provided by that library. If a library hasn't been updated to provide a global variable yet, it means that needs to happen first. After all calls to LibStub have been removed, the LibStub files can be deleted from the addon and all remaining traces removed from the manifest.
Report comment to moderator  
Reply With Quote
Unread 02/24/20, 10:01 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1317
File comments: 845
Uploads: 35
Originally Posted by desertforce
Hi... I've got a question...

For removing the LibStub:

For an Addon to keep working, will it be only necessary to change the entries within the *.txt manifest before removing the "Libstub" folder from the addon or will it be necessary to change more..?

Just asking because if only the *.txt manifest needs to be changed I could do it myself without the need to wait for an update from the author ... But if it would take more, then I would need to wait for updates or try to look for new/other addons to replace some older ones ...

Best regards
De-chan
Removing LibStub will require changes to the addon code. In most cases it should be as simple as finding the line where LibStub is called (as explained in the LibStub addon description) and replace it with the global variable provided by that library. If a library hasn't been updated to provide a global variable yet, it means that needs to happen first. After all calls to LibStub have been removed, the LibStub files can be deleted from the addon and all remaining traces removed from the manifest.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Report comment to moderator  
Reply With Quote
Unread 02/24/20, 09:28 AM  
desertforce

Forum posts: 3
File comments: 76
Uploads: 0
Hi... I've got a question...

For removing the LibStub:

For an Addon to keep working, will it be only necessary to change the entries within the *.txt manifest before removing the "Libstub" folder from the addon or will it be necessary to change more..?

Just asking because if only the *.txt manifest needs to be changed I could do it myself without the need to wait for an update from the author ... But if it would take more, then I would need to wait for updates or try to look for new/other addons to replace some older ones ...

Best regards
De-chan
Report comment to moderator  
Reply With Quote
Unread 01/03/20, 03:33 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1317
File comments: 845
Uploads: 35
Correct. I have updated the addon description to reflect this.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Report comment to moderator  
Reply With Quote
Unread 01/02/20, 02:07 AM  
votan
 
votan's Avatar
AddOn Author - Click to view AddOns

Forum posts: 503
File comments: 1269
Uploads: 33
Originally Posted by Edorenel
I'm uncertain the workings of add-ons and libraries. So, forgive me for my noob question. *Blushes* But will this add-on update to The Elder Scrolls Online v5.2.11 (or 5.2.5, according to some of the current, most popular add-ons)?
Hi @Edorenel,

there is no need to update the lib. The code did not change for years. We are about to get rid of this lib anyway.
Just alllow older API-Version (called out-dated) addons, by checking the checkbox in the extension menu.
__________________
@votan73 (EU - megaserver)
Report comment to moderator  
Reply With Quote
Unread 12/30/19, 05:09 PM  
Edorenel
 
Edorenel's Avatar

Forum posts: 0
File comments: 10
Uploads: 0
I'm uncertain the workings of add-ons and libraries. So, forgive me for my noob question. *Blushes* But will this add-on update to The Elder Scrolls Online v5.2.11 (or 5.2.5, according to some of the current, most popular add-ons)?
__________________
“Tomorrow may be hell, but today was a good writing day, and on the good writing days nothing else matters.” - Neil Gaiman


Like my writings? Support me on Ko-Fi!
Website: Edorenel
Report comment to moderator  
Reply With Quote
Unread 12/04/19, 04:40 PM  
charlie_rowland

Forum posts: 0
File comments: 2
Uploads: 0
LibStub Info

Hello,

I was wondering:

I have downloaded LibStub and copied the folder to my AddOns folder. Is it safe to delete the extra 9 LibStub folders in various other AddOn folders? Won't that speed up my load time?

Thanks!

Just deleted them. Everything seems to be working. Lost 2 seconds on load time, not that great since it still took 90 seconds but it is something.
Last edited by charlie_rowland : 12/04/19 at 06:14 PM.
Report comment to moderator  
Reply With Quote
Unread 05/21/19, 04:14 PM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1317
File comments: 845
Uploads: 35
Originally Posted by Rhyono
Since a lot of authors will probably still come look at LibStub and you're already advising them to use AddOnVersion: you should probably mention IsLibrary too.
Good idea. I added something to the addon description.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Report comment to moderator  
Reply With Quote
Unread 05/21/19, 04:06 PM  
Rhyono
AddOn Author - Click to view AddOns

Forum posts: 586
File comments: 1166
Uploads: 19
Since a lot of authors will probably still come look at LibStub and you're already advising them to use AddOnVersion: you should probably mention IsLibrary too.
Report comment to moderator  
Reply With Quote
Unread 05/21/19, 07:39 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1317
File comments: 845
Uploads: 35
Originally Posted by DBZVelena
All your LibStub depending addons should now work when you don't have "allow outdated addons" box ticked.
Or you could just tick that checkbox, which does exactly the same thing. It disables the comparison of the APIVersion in said txt file, which has the same effect as changing the number.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Report comment to moderator  
Reply With Quote
Unread 05/21/19, 07:33 AM  
DBZVelena

Forum posts: 1
File comments: 19
Uploads: 0
Its that time again.

to get your addons to work that depend on this bit of outdated stuff.

Go to: C:\Users\[whatever username]\Documents\Elder Scrolls Online\live\AddOns\LibStub

open LibStub.txt file. You can just use any text editing program.

Change the first line: ## APIVersion: 100025 100026
to: ## APIVersion: 100026 100027

save file.

close file.

Start up eso.

All your LibStub depending addons should now work when you don't have "allow outdated addons" box ticked.

This works for any addon btw, however it wont make lua errors go away. so use with caution.
Report comment to moderator  
Reply With Quote
Unread 11/03/18, 08:53 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1317
File comments: 845
Uploads: 35
Re: Creating a library without LibStub

Originally Posted by tomtomhotep
Originally Posted by sirinsidiator
Addon Authors: LibStub is no longer needed if you plan to write a new library.
This confuses me a bit. How would I do this. I just declare my own global table and hope I gave it a unique-enough name?

I thought the main purpose of LibStub was to take all those table references and stuff them into one big Global table named LibStub, to avoid Globals Pollution?


Also, if I write a library with it's own global table, then it can NEVER be bundled inside another addon. It must be loaded as a standalone addon (which many addon authors are moving towards, but they're not all there yet).
Global namespace pollution never was a major concern in this context and you had to make sure that you use a unique name for the library anyways if you wanted to register it with LibStub. The entire purpose of it was versioning of the library code.

When multiple addons contain some version of the lib and each loads the files from its own manifest, you somehow have to make sure that only the newest version of the code is used. That's what LibStub was made for. However, since a year ago the game itself supports loading of nested addons and you can specify an "AddOnVersion" inside the manifest so it only loads the newest version.

This means you no longer need to add the library files to your addon manifest, but instead can just mark it as a dependency in the manifest via the "DependsOn" directive and let the library handle loading of its own files since it basically has become a full fledged addon. Which also means you can now use xml for ui elements, split the library code into multiple files, use saved variables and no longer have to worry about bugs from old library versions getting carried over, since only the latest code is loaded by the game.

Authors can still put the library inside their own addon if they wish so, since the game will just load it from within the addon folder (as long as it's not nested too deeply), but recently many have opted to move them out, since it means that updating them whenever a new version is uploaded to ESOUI is no longer tied to releasing a new version of dependent addon. Meaning the new library version arrives faster at the users end since it is handled by minion, or users should be aware that they have to check for library updates too.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Report comment to moderator  
Reply With Quote
Unread 11/03/18, 08:29 AM  
Baertram
 
Baertram's Avatar
AddOn Author - Click to view AddOns

Forum posts: 2646
File comments: 3102
Uploads: 57
Re: Creating a library without LibStub

Half correct. You can bundle the lib with your addon but it needs its own txt file with the ## AddOnVersion: tag!
Which Imo makes no sense to bundle it then! Just install it as standalone.

And libStub is not cleaning global name's pace. Each addon with global variables will be still in _G after libs tub loaded it (libraries as well). LibStub just adds the libs to its own global namespace so you can easily access it + check the version and overwrite older major/minor version combinations (where major is the library name most of the time) with newer minor versions. This way you always assure the newest version is loaded no matter if standalone, in subfolders loaded by own libraryName.txt, or in subfolders loaded by the main addonName.txt.

About the new library:
I guess you are right. Create a global variable/table yourLib = {} and add the infos to it. As long as it got a txt with the ##AddOnVersion: it will check the newest version from this info and overwrite the existing global table.
You could also declare it like this to keep existing data already yourLib = yourLib or {}. But this won't overwrite then!
So a newer version could only add data but not overwrite it.

Originally Posted by tomtomhotep
Originally Posted by sirinsidiator
Addon Authors: LibStub is no longer needed if you plan to write a new library.
This confuses me a bit. How would I do this. I just declare my own global table and hope I gave it a unique-enough name?

I thought the main purpose of LibStub was to take all those table references and stuff them into one big Global table named LibStub, to avoid Globals Pollution?


Also, if I write a library with it's own global table, then it can NEVER be bundled inside another addon. It must be loaded as a standalone addon (which many addon authors are moving towards, but they're not all there yet).
Last edited by Baertram : 11/03/18 at 08:33 AM.
Report comment to moderator  
Reply With Quote
Unread 11/03/18, 08:10 AM  
tomtomhotep
 
tomtomhotep's Avatar
AddOn Author - Click to view AddOns

Forum posts: 21
File comments: 209
Uploads: 6
Question Creating a library without LibStub

Originally Posted by sirinsidiator
Addon Authors: LibStub is no longer needed if you plan to write a new library.
This confuses me a bit. How would I do this. I just declare my own global table and hope I gave it a unique-enough name?

I thought the main purpose of LibStub was to take all those table references and stuff them into one big Global table named LibStub, to avoid Globals Pollution?


Also, if I write a library with it's own global table, then it can NEVER be bundled inside another addon. It must be loaded as a standalone addon (which many addon authors are moving towards, but they're not all there yet).
Report comment to moderator  
Reply With Quote
Unread 11/03/18, 04:12 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1317
File comments: 845
Uploads: 35
Originally Posted by F-Lambda
Originally Posted by Dolgubon
Originally Posted by SteveCampsOut
Is this lib even necessary anymore? It hasn't been updated since 2014. I'd like to delete it.
Yes, very much so. If you remove it, almost every single library you have will not work.
Is this still the case, seeing as the add-on description reads "LibStub is no longer needed if you plan to write a new library" at the top.
This is directed towards authors who are creating a new library. Existing libraries that are based on LibStub will always require it as a dependency, until they are updated to no longer depend on it.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Last edited by sirinsidiator : 11/03/18 at 04:13 AM.
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: