-
Notifications
You must be signed in to change notification settings - Fork 0
Modules
No one wants to write code multiple times, right? Jask allows the definition of modules, a jask file containing code, which can be imported in other jask scripts:
; file math.jask
function power(base: number, exponent: number)
; implementation goes here...
endThis file can now be imported in another script:
; file main.jask
use "math.jask" as math
print(math::power(2, 3)Note that you can choose the identifier for an imported module freely. It is recommended to use an identifier, which is recognizable and meaningful for your purposes.
When importing a module via use, the interpreter checks in the following order:
- Absolute paths to modules are always prioritized
- If it is a relative path, the interpreter checks if the file is next to the importing file
- If a file is not found under 2., the interpreter checks if the file is located relative to the starting process. Imagine the following directory:
/ (root)
├── usr/
│ └── local/
│ └── lib/
│ └── date.jask
└── home/
└── user/
└── jasksharp/ <-- (working directory for interpreter)
└── jcore/
├── date.jask
└── myJaskProject/
└── main.jask
The file main.jask can import the module date.jask via an absolute path or via the relative path jcore/date.jask.
The second case is relative to the interpreters working directory, so the file is found.
Jask consists not only of the interpreter, but also of a collection of helpful functions known as jcore. Jcore bundles a lot of common functionality, which is purely written in jask. It is meant as a demonstration of jasks capabilities and features. If you have implemented a usefull feature, help expanding jcore via a pull request!
Global variables in modules are not accessible from scripts importing the module. Imported modules from other modules are too, not accessible from scripits importing the module. Example: Module a importing module b. Script a importing module a can access all structs and functions but not implicitly module b. Structs, however, are globally accessible.