Auto-loading AVSLib and/or custom AVSLib configurations
It may not be immediately apparent from the documentation, but there is nothing that prevents you from loading AVSLib automatically from the Avisynth plugins directory, or from creating your own configurations to load either explicitly or automatically. You just have to perform a few easy steps.
The best way to show how this can be done is by example. Therefore, the rest of this article presents three specific examples:
- Autoload entire AVSLib library, to be always available in your scripts without further work.
- Create a custom configuration that should always be available and autoload it.
- Create a set of custom configurations and a custom loading function to call as the first line of your script.
Example 1: Autoload entire AVSLib library
You just have to create an .avsi file (the name can be anything, for example: myavslib.avsi) with the following contents:
LoadLibrary("avslib", CONFIG_AVSLIB_FULL)
Copy this file to your Avisynth plugin directory and you are done. The next time you will load a script all AVSLib functionality will be ready to be used, without needing to explicitly call LoadModule, LoadPackage or LoadLibrary functions.
Example 2: Create a custom AVSLib configuration and autoload it
Suppose you find yourself constantly using the following AVSLib components: arrays, filters, string functions and also debug functions when debugging scripts.
You then just have to create an .avsi file (the name can be anything, as above) with the following contents:
LoadPackage("avslib", "array") LoadPackage("avslib", "debug") LoadPackage("avslib", "filters") LoadPackage("avslib", "string")
Afterwards, copy this file to your Avisynth plugin directory and this is it. From now on every time you load a script all needed AVSLib functionality will be ready to be used, without explicit calls to loader routines.
Example 3: Create a set of custom configurations and a user-defined loading function
To make an example, lets suppose that you scripts use regularly three disctinct configurations:
You can then easily construct, using block statements, a custom loading function, like the one below:
# config must be 0,1,2 function myAvsLib(int config) { return config == 0 ? Eval(""" LoadPackage("avslib", "array") LoadPackage("avslib", "filters") """) : (config == 1 ? Eval(""" LoadPackage("avslib", "numeric") LoadPackage("avslib", "filters") """) : Eval(""" LoadPackage("avslib", "array") LoadPackage("avslib", "string") LoadPackage("avslib", "filters") """)) }Copy this function inside an .avsi file that you will save to your Avisynth plugin directory (any name for the file will do). Now you can use as the first line in your script the function to load the needed AVSLib configuration.
myAvsLib(0) ... {rest of script code} ...