@head @module loader @title loader: Dynamic loading of Alore code (deprecated) @note This module is deprecated and will be removed in the future. The compiler module will replace it. @end

This module enables dynamic compilation of Alore source code files. Dynamically loaded source files must follow the same conventions as ordinary Alore programs. They may import any modules imported by the program that loads the file and additional modules, potentially located in different directories. @note It is not safe to load source code from untrusted sources. Malicious code may read or delete your personal data files. @end

Functions

@fun Load(path as Str[, modulePath as Str]) as Module @desc Load an Alore source file. Return a Module object that allows accessing public variables, functions and classes defined in the file. If compilation fails, a @ref{CompileError} exception will be raised.

By default, the constant @ref{ModuleSearchPath} specifies the module search path. The optional argument can be provided to override the default module search path. The format of the argument is the same as the format of the @ref{ModuleSearchPath} constant. @end

Constants

@var ModuleSearchPath as Str @desc The default module search path. It is a string that contains module search directories separated by @ref{os::PathSeparator}. The directories are searched from first to last to find imported modules. @note This constant is empty ("") if the program currently being executed is standalone, i.e. it was compiled using alorec. @end @end @class-hidden Module

Class Module

The Module class provides these members and operations: @fun contents() as Array @desc Return an array of the names of public global definitions in the source file. This includes variable, constant, function and class definitions. The order of the result is unspecified. @end @op module[name] @optype{Module[Str] -> dynamic} @desc Return the value of public global definition. The name argument is the name of the definition as a string. Raise an KeyError exception if there is no public global definition with the specified name. @end @end-class

Exception CompileError

@class CompileError(errorMessages as Array) @desc Construct a CompileError instance. Messages should be an array of error message strings. CompileError inherits from @ref{std::Exception}. @end

CompileError members

@var errorMessages as Array @desc Constant member that contains compilation error messages as an array of strings. @end @end-class

Shared modules and garbage collection

Dynamically loaded code may not compile new copies of any already imported modules. Therefore any global variables in modules are shared between all source files in a program, and module initialization is performed only once per module.

As an exception to this rule, if only a dynamically loaded source file or module refers to a module, and all references to code that may access this module (including Module objects, function objects and class instances) are removed, the garbage collector of the Alore runtime may free and destroy the module. In this case, a new copy of the module can be imported later.