Multiple Files - markpwns1/Dormez GitHub Wiki
You can use multiple files in a Dormez program. Observe:
utils.dmz
declare function add : a, b {
return a + b;
}
program.dmz
include "utils.dmz"
console.print(add(1, 2)); // prints "3"
The include
statement works by inserting the file's contents directly into the current file, right after the include
statement. If the same file is included twice, it will throw an error saying
File has already been included: <filename>
The include statement acts exactly like a function but without brackets, and as such evaluates any expression for its filename, as long as it's a string
. See the following example:
declare function includeWithoutExtension(filename) {
include filename + ".dmz";
}
Anything included in a file is automatically inserted into the global scope, so the example above works fine.
And finally, include
also works with ..
include "../../utils.dmz";