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:
local lib = LibStub:NewLibrary("MyLibrary-1.0", 1)
if not lib then
return -- already loaded and no upgrade necessary
end
function lib:SomeFunction()
-- do stuff here
end
function lib:SomeOtherFunction()
-- do other stuff here
end