Import

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (1 revision)
Line 15: Line 15:
 
'''Note 1''': Since the contents of the imported script are evaluated at the point of invocation, it is possible by enclosing the Import() call in a nested scope (for example inside a function) to make available to the importing script the functions and globals of the imported script ''without'' its script-level variables.
 
'''Note 1''': Since the contents of the imported script are evaluated at the point of invocation, it is possible by enclosing the Import() call in a nested scope (for example inside a function) to make available to the importing script the functions and globals of the imported script ''without'' its script-level variables.
  
'''Note 2''': Any script with the AVSI extension in the AviSynth Plugins folder is automatically imported. This is useful for making script functions available to any new script you create without having to copy and paste.
+
'''Note 2''': Any script with the [[AVSI]] extension in the AviSynth Plugins folder is automatically imported. This is useful for making script functions available to any new script you create without having to copy and paste.
  
 
[[Category:Internal filters]]
 
[[Category:Internal filters]]
 
[[Category:Media file filters]]
 
[[Category:Media file filters]]

Revision as of 23:54, 20 September 2014

Import(string filename [, ... ])

Import evaluates the contents of other AviSynth scripts at the point of invocation.

Functions, variables and loaded plugins declared inside the imported script are made available to the importing script. In addition, the return value of the function is the last value of the last filename script (a clip or whatever the filename script chooses to end with). The latter can be assigned to a variable of the importing script and manipulated (this is most useful when the imported script ends with a clip).

The current working directory (CWD) is saved and set to the directory containing the script file before compiling the script. The CWD is then restored to the saved directory.

Some indicative uses of Import include:

  • Storing multiple script-functions, variables and global variables for reuse by scripts (creation of script libraries).
  • Retrieving pre-built streams.
  • Retrieving dynamically configured pre-built streams (the core idea is that the importing script declares some global variables which the imported script uses to configure the stream that will return).

Note 1: Since the contents of the imported script are evaluated at the point of invocation, it is possible by enclosing the Import() call in a nested scope (for example inside a function) to make available to the importing script the functions and globals of the imported script without its script-level variables.

Note 2: Any script with the AVSI extension in the AviSynth Plugins folder is automatically imported. This is useful for making script functions available to any new script you create without having to copy and paste.

Personal tools