This is an old revision of the document!
The terms module and addon are used synonymously throughout the document. The addon is basically a lua module turned private (closed source). If you want to distribute or sell your module through our addon store, it will have to be adjusted to work. This document contains basic information on what needs to be done.
When a module is converted into an addon the following things will happen:
CreateFolders: If you want to create subfolders on the local hdd to write logfiles or export files from inside your module, you can define a list of subfolders (single level) inside the .def file. Those folders will be created inside your modules local folder.
Example:
CreateFolders=log,settings,files
ExportFiles: If you have files inside your module that need to be accessible from the local hdd of the user, you can have them exported. Files will always be exported from the folder you put them in and into the same local folder inside the module folder. You need to use the CreateFolders option to create any local folders or the export will fail. Files will be overwritten when your module is loaded, so don't export files that the user should be able to edit. Files and folders can only contain alphanumerical letters.
Example:
ExportFiles=files/PlayerAlert.wav
Important: The “Name” entry in the .def file will be used to create your modules local folder. So pick a name that identifies your module properly. The name defined in the module.def file will be the name that the module is published in the addon store. If you want to load a local file, the path can be build as follows:
local path = GetStartupPath() .. [[\LuaMods\{modulename}\]]
All lua files in your module will be merged into a single file in the order they appear in the .def file. This will change the scope of your file local variables. Anything decleared as local inside one of your files (on file level, not function level) will now be local to the single large file. This makes your module use its own scope, that is not global, but you can still access all file local variables like globals inside your modules code. If you want to keep your modules data private, define your modules main table as local (see example below).
For testing purposes and debugging you can either merge your lua files into one file or just use globals instead of local variables.
A new function has been added to provide you with functions to load files from inside your module. To get the functions to load and list files you need to call GetPrivateModuleFunctions() at load time of your module. It will return a table containing all functions avaialable to your module.
Important: DO NOT STORE THE PRIVATE MODULE FUNCTIONTABLE IN A GLOBAL VARIABLE UNLESS YOU WANT EVERYBODY TO BE ABLE TO LOAD FILES FROM INSIDE YOUR MODULE !
Currently there are two function:
ReadModuleFile: Loads a single file from inside your module. It expects a table containing the keys p,m,f p: the folder inside your module f: the filename of the file you want to load m: the module name (not used) It will load the file into a lua string that can be parsed or passed to loadstring to be executed GetModuleFiles: Get all files inside the "data" subfolder. The function returns a table containing table entries having the keys p,m and f, with p=folder,m=modulename,f=filename, for each file in the folder. Entries from this table can be passed to the ReadModuleFile function to load those files. The modulename is not used, you can only load files inside your own module.
Here is an example of how to declare a local module main table and use the private module functions to load a file from inside the module:
Define your modules main table as local to protect it from outside access:
local modexample = {} -- defined as local, not accessible outside the file modexample.ModuleFunctions = GetPrivateModuleFunctions() -- since modexample is local, so is ModuleFunctions
Modified loading function for persisted lua tables:
function modexample.LoadPersistentTable(name) if (modexample.ModuleFunctions ~= nil and modexample.ModuleFunctions.ReadModuleFile ~= nil) then local fileInfo = { p = "data" , m = "MyModule" , f = name } local fileString = modexample.ModuleFunctions.ReadModuleFile(fileInfo) if (fileString) then local fileFunction, errorMessage = loadstring(fileString) if (fileFunction) then jtb[name] = fileFunction() else jtb[name] = {} end end end end
Load a lua table stored with the persistance function:
modexample.SGD = modexample.LoadPersistentTable("SecretGameData.lua")
Get all files inside the “data” subfolder of your module:
local filelist = modexample.ModuleFunctions.GetModuleFiles("data");