Skip to content

Modules

Julius Paffrath edited this page Jul 4, 2026 · 9 revisions

Introduction

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...
end

This 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:

  1. Absolute paths to modules are always prioritized
  2. If it is a relative path, the interpreter checks if the file is next to the importing file
  3. 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 standard libraries jcore

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!

Encapsulation

Global variables in modules are not accessible from scripts importing the module. Structs, however, are globally accessible.

Clone this wiki locally