Thread Tools Display Modes
07/03/14, 04:42 AM   #1
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
[Request]LibConstantProvider

We can provide bulk data for our addons functionality in a seperate .lua file, by assigning the data to a global Variable in the .lua file. Something like this:
Lua Code:
  1. OurAddonConstants = {
  2.   --insert really big table here
  3. }
We are supposed to use this in particular for localisation (with the idea that the the proper languages .lua file is loaded based on client langauge and manifest entry):
Code:
localization/$(language).lua
On the plus side this allows us to split large amount of default data (like where each Skyshard/Lorebook can be found) over multile files.
On the downside this does pollute the global namespace with a lot of constants (at least 1 per addon; possible 1 more for Localisation uses). And if there is one thing I don't like it is a untidy global namespace.

LibStub allows us to share libraries across Addon barriers. It also ensures only the most current version is used. But very important for me it also keeps the global namespace clean - the only thing that is needed is the global variable that holds libStub itself. Via it you can request every library, wheter you provided it with your addon or it was installed stand alone.
LibMediaProvider does something similar for Media like Fonts, Textures and sounds (once they get implemented).

Would anybody be interested in writing such a library?
Could LibMedia Provider be expaneded for another read only type called "Lua Data"?
  Reply With Quote
07/03/14, 05:53 AM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
If I understand you correctly, there's no need for a separate library, LibStub is enough.

Lua Code:
  1. -- myaddondata.lua
  2. local data = LibStub:NewLibrary("MyAddonData-1", 1)
  3. if not data then return end
  4.  
  5. -- fill it ...

Lua Code:
  1. -- myaddon.lua, or someoneelsesaddon.lua, that wants to use myaddondata
  2. local data = LibStub:GetLibrary("MyAddonData-1")
  Reply With Quote
07/03/14, 06:09 AM   #3
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by merlight View Post
If I understand you correctly, there's no need for a separate library, LibStub is enough.

Lua Code:
  1. -- myaddondata.lua
  2. local data = LibStub:NewLibrary("MyAddonData-1", 1)
  3. if not data then return end
  4.  
  5. -- fill it ...

Lua Code:
  1. -- myaddon.lua, or someoneelsesaddon.lua, that wants to use myaddondata
  2. local data = LibStub:GetLibrary("MyAddonData-1")
That is an interesting solution and something I can work with.
However, I think this is not a longterm solution. While the lib Stub ID strings are a slightly less crowded area, there might still be colissions. And if we have colissions there we either loose some data or one of the libraries.
  Reply With Quote
07/03/14, 07:21 AM   #4
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
There might be collisions in any namespace. It depends only on how users of that namespace behave. If someone decides to publish their data under the name "Foo", or to hijack someone else's well-known identifier, no library can fix it. You could enforce something like tag:uri in a library, but I think anyone who doesn't enjoy shooting themselves in the foot, also doesn't name their globals Foo.
  Reply With Quote
07/03/14, 01:05 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Originally Posted by merlight View Post
If I understand you correctly, there's no need for a separate library, LibStub is enough.

Lua Code:
  1. -- myaddondata.lua
  2. local data = LibStub:NewLibrary("MyAddonData-1", 1)
  3. if not data then return end
  4.  
  5. -- fill it ...

Lua Code:
  1. -- myaddon.lua, or someoneelsesaddon.lua, that wants to use myaddondata
  2. local data = LibStub:GetLibrary("MyAddonData-1")
That is creating a library.


@zgrssd: LibMediaProvider is for media and media only. We won't be working localizations into there.

Libraries work best when specialized. Media (bar textures, fonts, etc.) is something that a user would want access to across all their addons that have options for those media types. General localization shouldn't be a library (settings names, etc.). Specific localization could be a library (locations or items).
  Reply With Quote
07/03/14, 04:22 PM   #6
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by Seerah View Post
@zgrssd: LibMediaProvider is for media and media only. We won't be working localizations into there.
Localisation is just one minor side use for a "LibConstantProvider". Any bigger table/amount of data is worth being put into a seperate .lua file. Just that this would pollute the global namespace is preventing that.
Localisation is just one class of runtime constan data it could deal with.

I guess the biggest issue would be:
When upgrading to a higher library version, how do I preserve the data that was registered with the previous version?
  Reply With Quote
07/03/14, 06:25 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
It's still stored in that table.
  Reply With Quote
07/04/14, 02:41 AM   #8
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by Seerah View Post
It's still stored in that table.
After some thinking I think I get it now for libStub:
You create one table when a major library is first registered. You store all data into it using self.varname.
When upgrading the library or handing it out to consuming code, you just hand out the table again.
  Reply With Quote
07/04/14, 09:41 AM   #9
Halja
 
Halja's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 111
You can separate the data to many files if you want. The manifest order is important. Here is a general approach.
In the txt file.

Code:
## Title: Do Someting Interesting Addon
## Author: XXXXX
## Version: XXXX
## APIVersion: 100007
## SavedVariables: SomeSavedVariables

IAddon.lua
IAddonExternalDataFile.lua

First lines or so of IAddon.lua.
Code:
MyAddon = {
	Title = "Do Someting Interesting Addon",
	AnotherVar = "Derp!",
}

Now in IAddonExternalDataFile.lua you reference the single table of your addon.
Code:
MyAddon.UI = {
	["MainWindow"] = 
	{
		["WindowWidth"] = 305,
		["WindowHeight"] = 215,
	},
}
Your impact to the Global name space is the root table point. The cool thing about the localization variable is only the target language file is loaded. Even here you could leverage several files if you wanted too.
  • MyAddonStringListEN.lua
  • MyAddonStringListDE.lua
  • MyAddonStringListFR.lua
  • MyAddonMethodsEN.lua
  • MyAddonMethodsDE.lua
  • MyAddonMethodsFR.lua

Placing MyAddonStringList$(language).lua and MyAddonMethods$(language).lua in the manifest would load two files.
--Helja
  Reply With Quote

ESOUI » AddOns » AddOn Search/Requests » [Request]LibConstantProvider


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