Thread Tools Display Modes
01-28-10, 12:51 PM   #1
Amenity
Guest
Posts: n/a
Addon file system structuring

I'm sure this has probably come up at some point but I couldn't find anything on it in my searches...so sorry if this is oft-repeated.

Hypothetical scenario: I've got a clock addon. Due to my anal-retentiveness, it's separated into the following files:

clock.lua --All the frames & appearance-related stuff defined here.

thingus.lua --The actual timing function.

clock.toc --Self-explanatory.


1. Is there any reason not to do this?

2. When loading multiple Lua files in a single addon, are they simply appended to the preceeding file in-order as defined in the ToC? Or are they handled as "separate addons"? Example with two files:

Code:
local thingus = somevalue
Code:
function dostuff(when)
    print(thingus)
end
Will that toss an error? Or is the second file appended to the end of the first, making thingus a defined value for the dostuff function?

3. Assuming an addon of considerable size, is it better to have many small files or a few/one large file?

4. Assuming file structure "matters", how does directory structure factor into this?

Thanks in advance!

Last edited by Amenity : 01-28-10 at 12:54 PM.
  Reply With Quote
01-28-10, 12:57 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 6,007
They are loaded in the sequence listed in the TOC but local entities in one file can only be accessed via another file if there is a non lock function to grab them.

I have used that functionality with my LootAlerter addon with all the data in one file, common functions in another etc. The downside is that functions that you want to use outside of the file will mean they are in the public domain and naming conflicts could get in the way. The upside is that the code is separated for easier access to source data.

If the addon will be less than 500 or even more lines stick with just the one file to avoid the non local issue at least. If you do need them split up, try and find a way to maximize the use of the local option so that only what you need to be public is public and that it is unique to your addon enough for it not to get mixed up.

I've course that is just my view and understanding on things. I have always learning that local is good. The more localised the better.
__________________


All Level 70 Characters:
Demon Warlock
Resto Druid
Disc Priest
Resto Shaman
Survival Hunter
Augment Evoker
Frost Mage
Vengence Demon Hunter
Rogue ( was subtlety )

Brewmaster Monk (TR)
Prot Paladin (TR)
Blood Death Knight ( TR)

As you can see I am missing a warrior

And .. I don't have all the allied races covered. Time Runner time when it happens again

  Reply With Quote
01-28-10, 01:02 PM   #3
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
New file, new variables. Nothing is shared.
Last patch added an argument call to every file.
So there is a table you can use for all files and that
keeps values set in one file. I have an init.lua that I use
for nearly all new addons with something like this

Code:
local name, table = ...

if(name) then
  table.version = GetAddOnMetadata(name,"Version") or '0.0'
  table.author = GetAddOnMetadata(name,"Author") or '<Nobody>'
  table.appinfo = GetAddOnMetadata(name,"Notes-"..GetLocale()) or GetAddOnMetadata(name,"Notes") or '<No Info>'
  table.title = GetAddOnMetadata(name,"Title-"..GetLocale()) or GetAddOnMetadata(name,"Title") or name
  table.character = UnitName("player")
  table.crealm = GetRealmName()
  table.faction,_ = UnitFactionGroup('player')
end
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
01-28-10, 01:06 PM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 6,007
Oh, not heard about that. So ... are the values contained in that table at that time ?

So I could keep my data separate and localized and it will be accessible in other files loaded after ? Or am I missing something ?
__________________


All Level 70 Characters:
Demon Warlock
Resto Druid
Disc Priest
Resto Shaman
Survival Hunter
Augment Evoker
Frost Mage
Vengence Demon Hunter
Rogue ( was subtlety )

Brewmaster Monk (TR)
Prot Paladin (TR)
Blood Death Knight ( TR)

As you can see I am missing a warrior

And .. I don't have all the allied races covered. Time Runner time when it happens again

  Reply With Quote
01-28-10, 02:25 PM   #5
Amenity
Guest
Posts: n/a
Originally Posted by Xrystal View Post
Oh, not heard about that. So ... are the values contained in that table at that time ?

So I could keep my data separate and localized and it will be accessible in other files loaded after ? Or am I missing something ?
I'm a bit confused myself. How exactly is that method any different from any other local variable generation in a previously-loaded file? Looks like you're just making a table. What am I missing?
  Reply With Quote
01-28-10, 02:31 PM   #6
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,711
The table is kinda a local global, for usage within any files of the addon in question.

No matter what file you add stuff to that table it will stick to all files.

Its very good to use for stuff like embedding and localization.
  Reply With Quote
01-28-10, 02:41 PM   #7
Shadowed
...
Premium Member
Featured
Join Date: Feb 2006
Posts: 387
It's a way of making your addon more self contained, before if you spread an addon out between multiple files you had to have a global somewhere.

Before you would have to do something like:

Code:
-- localization.enUS.lua
AddonLocals = {["foo"] = "foo"}

-- Addon.lua
local Addon = {}
local L = AddonLocals
Now you can do:

Code:
-- localization.enUS.lua
local Addon = select(2, ...)
Addon.L = {["foo"] = "foo"}

-- Addon.lua
local Addon = select(2, ...)
local L = Addon.L
It really just gives you cleaner syntax.
  Reply With Quote
01-28-10, 02:47 PM   #8
Amenity
Guest
Posts: n/a
Originally Posted by p3lim View Post
The table is kinda a local global, for usage within any files of the addon in question.

No matter what file you add stuff to that table it will stick to all files.

Its very good to use for stuff like embedding and localization.
Right, I understood that part. My sense of confusion is how it does this.

I think my confusion has to do with my ignorance of calling name as an argument to if. In other words, he's doing this:

Code:
local name, table = ...

if(name) then
    blahblahtablecrap
end
And I'm thinking this:

Code:
local name, table = ...

if name then
    blahblahtablecrap
end
I'm also assuming that ellipsis use in Lua is similar to C (i.e., "variable number of whatever").
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Addon file system structuring


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