#import and #load

Modules are stored in the compiler directory under jai/modules/.
Modules can be imported via #import "ModuleName";.
You can create your own module but simply putting it in jai/modules/.
This can also be done inside a folder jai/modules/YourModuleFolder/. In this case, you need to have a module.jai inside the folder.
Modules can be assigned to identifiers e.g. Math :: #import "Math";. Then everything inside the module will be namespaced with the given name, e.g. Math.sqrt(...).
Additional modules from other directories can be imported via the -import_dir "Path/To/Module" flag, e.g. to load a module.jai in the same folder:

jai hello_world.jai -import_dir "./"

You can load any jai-file via #load, e.g. #load "my_file.jai";. The path is relative to the calling file.
Think of loading a file as pasting the code directly into the calling file: If you load two files

#load "file_a.jai";
#load "file_b.jai";

then all (exported) functions/structs/globals of file_a will be available in file_b and vice versa.

Named #import

You can name modules that are imported. A named #import allows you to namespace function. This allows you to resolve namespace collusions in code.

Math :: #import "Math";
y := Math.sqrt(2.0);
1 Like