Go to Page... |
Compatibility: | Harrowstorm (5.3.5) 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: | 6,003 |
Total downloads: | 1,420,163 |
Favorites: | 1,007 |
MD5: |
## AddOnVersion: 6 ## IsLibrary: true
Returns:IterateLibraries()
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
Returns:NewLibrary(major , minor)
An iterator over the registered major libraries.
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
LibAddonMenu-1.0
... and hopefully many more to come!
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
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 |
Comment Options |
06/30/14, 11:18 AM | |
|
Need some info on LibStub usage
Since I was never part of the WoW Addon community, so I had some questions regarding how exactly libStub works.
The features I could identify so far: If you have more then instance of the same library (local copy and several embedded ones), Stub makes certain only the most current stays in memory. That also means some minor loadigntiem increase, as already loaded embedded libs do not have thier code executed again. It also keeps the global namespace clean. Nothing about the lib needs to be globally exposed, as libStub is globaly exposed and can hand out references. Now to my questions (specifically towards the examples): Code:
local lib = LibStub:NewLibrary("MyLibrary-1.0", 1) if not lib then return -- already loaded and no upgrade necessary end A reference to a libs Table to assign your libs functions too. Or nil/false in case this lib (with same or higher version) has already been run Here you check if the return values is nil or false and then just cancel the .lua files execution (hence prevent older version from overwriting newer ones and save some processing time). Code:
function lib:SomeFunction() -- do stuff here end function lib:SomeOtherFunction() -- do other stuff here end http://www.lua.org/pil/15.1.html Could I also assign them like this: Code:
local function SomeFunction() -- do stuff here end local function SomeOtherFunction() -- do other stuff here end lib.SomeFunction = SomeFunction lib.SomeOtherFunction = SomeOtherFunction This will always only get me a refence to the highest version of hte library currently loaded. But will this be a clone of the table currently registerd in LibStub, or the real table (wich means I have to look out not to assign anything). Also what happens with the reference if a never version is loaded only after I called GetLibrary? Would the functions calls still target the previous version of the lib, or would even that "old" reference link to the new functions? I generally call it in the OnLoaded event only, but I don't know if others might call it in code. You also say "don't set LibStub as OptionalDependsOn", but I wonder why? Is it not properly versioning itself? Should I install a local copy of libStub? (the idea is that usually local copies are more likely up to date then embedded ones; and with optional dependencies libStub can get the local copy first). What happens if a local copy is loaded by pure chance before the last embedded is run? What if the local copy runs last by pure chance?
Last edited by zgrssd : 06/30/14 at 11:20 AM.
|
|
zgrssd |
View Public Profile |
Send a private message to zgrssd |
Find More Posts by zgrssd |
Add zgrssd to Your Buddy List |