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) 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! :) |
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. |
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 = ... |
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 ? |
Quote:
|
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. |
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 Code:
-- localization.enUS.lua |
Quote:
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 = ... Code:
local name, table = ... |
Very interesting. So where is the original information on this as I can't see it in the UI forums 3.3 changes.
What other values are in ... From the looks of it the first argument is the addon's name and the second one is its global table. Any other information in there ? So say in my localization.enUS.lua file I currently do this. <MyAddon>Translator_L["DescriptiveName"] = "Translated Text" And then in my main addon I would usually do something like this. local _L = <MyAddon>Translator_L; print(_L["DescriptiveName"]) Instead I can now do this ? AddonData = select(2,...) AddonData.Translator_L["DescriptiveName"] = "Translated Text" AddonData = select(2,...) local _L = AddonData.Translator_L; As long as each file in that addon you want to update and/or use the addons data will need to add that first line each time? So in essence they have created a global table for all addons that are loaded on the system ? Whether or not the values are used ? |
The parentheses are unnecessary in the same manner as a semicolon is unnecessary - in most cases. Only when attempting to disambiguate (in the case of an if) or use all on one line (in the case of semicolon when using /script within WoW) are they necessary.
|
Quote:
But yes, you could change it to that. |
Quote:
|
To better explain how WoW passes the new global vararg expression, I'm going to put up examples of before and after in context of function wrapping.
ToC File: Code:
File1.lua Code:
local function File1() Code:
local function LoadAddOn(AddOnName) |
rofl, might have to play with it a bit to get full understanding of it :D
basically we can now have every variable local and that addon table will allow us access ? Or am I still confused ? rofl |
Quote:
|
Do this in every file:
Code:
local addon_name, addon_table = ... Code:
function addon_table:PrintHello() Code:
addon_table:PrintHello() |
Aha, yep, thats what I envisioned, but kept forgetting functions are objects too :D
Might make some of my addons more cleaner working that way :D |
Oh, I don't believe I missed it rofl .. The amount of times I've read this post http://forums.worldofwarcraft.com/th...37376853&sid=1 and I never saw the part about the addon stuff.
Quote:
|
To reduce the confusion this part
Code:
if(name) then Dont know why I still have it ;) |
Rofl, thanks for the clarification there :D Was trying to think of times when it wouldn't exist :D
|
All times are GMT -6. The time now is 09:39 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI