A library is a script file which is loaded into other script files. A library is a unit of shared code.
Dividing your code into multiple parts and sharing these between projects will help to develop a sophisticated script with less cost.
For ModuleLoader, any files saved by Script Editor can be a library i.e. script files(.scpt files), script bundles(.scptd files), script applications and script source files(.applescript files). Any special code are not required for libraries.
ModuleLoader can minimizes code to manage and to load libraries with following features.
Woking with a few libraries using "load script" command may not problematic. But it is a painful task loading and managing several libraries which have some dependencies by "load script" command.
It is recommended to utilize ModuleLoader or "AppleScript Libraries" for loading libraries instead of "load script" command.
The default locations to search for libraries are follwing directories under user's home directory and root directory.
Also see the next section to add directories to locations to search for libraries.
The current settings of directries to search for libraries can be obtained with "module_paths" handler.
At first, consider to utilize a Local Loader. You can make flexibile locations to place libraries by the local loader.
If you want to add custom locations for libraries temporary, use set_additional_paths handler or prepend_path handler of the loader script.
If libraries are loaded through execution of "boot (module loader) for me" statement, same name libraries share same substance. This feature allow to minimize script size and to exchange data between libraries through a library.
An example will be shown. The following code is a loaded library.
In the following code, the library "ShareMessage" is loaded twice into two different properties. The property of one library of "ShareMessage1" is changed by set_message("hey"). The change affects the other library of "ShareMessage2". This means ShareMessage1 and ShareMessage2 share same substance.
If following files which have same name exists in Script Libraries, the priority to load is following order.