Imports
MC-Build supports importing of JavaScript, Templates, and libraries.
Importing JavaScript Files
import ./<path_to_file>.js
When importing a JavaScript file, the context exported via module.exports
will be injected into the JavaScript environment in the current file.
Examples
Importing a JavaScript File
my_js_file.js
module.exports = {
helloWorldString: "Hello, world!"
myIterator: function* () {
yield 1;
yield 2;
yield 3;
}
}
example.mcb
import ./my_js_file.js
function example {
say <% helloWorldString %>
}
REPEAT myIterator as i {
function <% i %> {
say I'm function <% i %>!
}
}
Importing Template Files
import ./<path_to_file>.mcbt
When importing a .mcbt
file, all the templates from that file will be loaded into the current file and made usable.
Examples
Importing a Template File
my_template.mcbt
template hello {
with arg1:word {
say Hello, <% arg1 %>!
}
}
example.mcb
import ./my_template.mcbt
function hello {
hello world
}
Importing Libraries
Warning
Libraries are Work-in-Progress. This section is subject to change.
import <library_name>
When importing a library by name, the code included in the library will be loaded and any templates from it will be added to the current file.
Examples
Importing a Library
example.mcb
import hello_world_lib
function hello {
hello world
}