EQWatcher Evolution > Scripting  > Function Imports


EQWatcher Evolution introduces the true "library" functionality for scripts.  Previously, EQWatcher scripts all physically contained their own version of every function, but now functions can be physically shared much the same way that public variables can.  Scripts that have functions imported by other currently loaded scripts cannot be unloaded by the user.

Importing Functions

The process of importing functions from other scripts is incredibly simple, and follows this form:

import [script].[function]([vartype][, vartype [. . .]]);

import [script].[function]([vartype][, vartype [. . .]]) as [mask];

Then calling this imported function can be done one of two ways:

script.function(parameters);

mask(parameters);

Example:


import dynarraylib.DAGetVersion();
import dynarraylib.DAResetArray(string) as DAResetArray;
import $dynarraylib.DAGetElementEx(string) as DAGetElement;

function main()
{
   unsigned long DAVersion=dynarraylib.GetVersion();
   string array;
   DAResetArray(array);
   // or
   dynarraylib.DAResetArray(array);
}


Function Libraries

A suggested use for this importing functionality is just like the dynarraylib library script.  dynarraylib.eas contains all of the actual functions used by dynarray, as well as a main() function.  The main function allows a debug line to be logged to EQWA.LOG when the library is loaded, and identifies the version and compile time of the library, and can of course serve most other initialization functions for the library.  dynarray.eas is the file intended for #including in scripts, and contains masked imports so that all scripts that previously used the dynarray functions will now use the library functions, seamlessly.

This separation of the actual functions from the include file, in EQWatcher Evolution terms is called a library.