Quantcast WoWInterface - View Single Post - Include files
Thread: Include files
View Single Post
09-12-18, 05:51 AM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,430
You can easily split them into several files.

As Vincent said, at the top of each file put

local addonName, addonData = ...

This allows each access to the addon wide data table


Function declarations will need to be defined before they are used but I think you can forward declare them where necessary.


You then specify the files in the order they need to be.


For example:
A toc file could contain something as follows:

Code:
file1.lua
file2.xml
file3.xml
file3.xml could then contain this


Code:
<UI xmlns="http://www.blizzard.com/wow/ui/"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
    <Include file = "Core.xml" />
    <Include file = "Features.xml" />    
</UI>
Core.xml could then contain this
Code:
<UI xmlns="http://www.blizzard.com/wow/ui/"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
    
    <!-- Items everything else requires access to -->
    <Include file = "Utils/Utils.xml" />
    <Include file = "Localization/Localization.xml"/>
    <Include file = "Options/Options.xml" />
</UI>

As you can see each file is included in the order it needs to be processed. Later files will call functions contained in earlier specified files etc.

The Utils.xml will hold a list of files that have individual unique but addon accessible functions
The Localization.xml will hold a list of localization related files which will include one that has an addon wide table to hold the active translation values used by other files
The Options.xml will hold a list of options related files which may need access to the localization files

Further core files can be added in the Core.xml file and the files listed in Features.xml will have access to everything that was included before it.

If the file you need is a code file you can use
<script file = "file1.lua" />

to add it to the list of files to load inside an xml file.

This is the only way I know of to 'include' files in a specified order

Here is an example of a frame that requires access to functions in a source file but is also used in another source file. For example if the frame display is controlled. Most of the time though only first first file is needed and the frame just passes itself to the functions it wants to work.

Code:
<UI xmlns="http://www.blizzard.com/wow/ui/"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://www.blizzard.com/wow/ui/">

    <!-- Include script file that will hold the functions called by the FrameToDisplay frame and functions within sourceFile2.lua -->
    <Script file = "sourceFile1.lua" />
    
    <!-- Layout of the FrameToDisplay Frame -->
    <Frame name="FrameToDisplay">
        ...
        <Scripts>
            <OnLoad>
                functionInSourceFile1(self);
            </OnLoad>
        </Scripts>
    </Frame>
    
    <!-- Include script file that acts on FrameToDisplayFrame -->
    <Script file = "sourceFile2.lua" />

</UI>
So to recap ..

TOC file can be used to list key xml/lua files in order of process
XML files can be used to include xml/lua files in order of process
Lua files are used to connect the individual code files by sharing a table amongst all the files

1. Define which parts are needed by everything ... they go in the earliest files
2. Define which parts are needed by most .. they go next
3. Define which parts are needed by some .. they go next
4. Define which parts are not needed by any .. they can go anywhere but best last
5. Define which parts are needed by some but needs others .. they go in between the related files .. after the ones they need and before the ones that needs them

I hope that helps you see how you can segregate your file into smaller files
__________________

Last edited by Xrystal : 09-12-18 at 06:40 AM.
  Reply With Quote