Documentation menu

Core Language

script, using, use & mylib

Start with one normal MAKO script. Give it a name only if you want one. When you need more tools, using connects a package, use makes one of your local files available, and mylib pulls a reusable library from GitHub. ModuMAKO adds its environment at the end.

New to coding?

Copy the examples exactly first. Run them. Then change one number or word and run them again. You are not expected to memorize the command lists.

1

script names your program

Begin with the file you run. script can give it a friendly name, but normal MAKO does not require one. This line only names the script; it does not load anything.

Try this code
# This program's friendly name is My First Game
script "My First Game";

main() {
    print "The game started!";
}

The filename and script name do not have to match.

2

using connects a package to this script

using means the current script will interact with a package. Write it at the top of the script. The package stays available to that script, and you call its commands with the package name and a dot.

Try this code
# Turn on these ready-made MAKO packages
using Mako2D;
using Inputs;
using Audio;

main() {
    Mako2D.init(800, 600, "My Game");  # Use a Mako2D command
}

using is for packages that interact with the script. If MAKO says a command requires using Physics3D, add using Physics3D; at the top.

3

use only responds when you talk to it

use makes another local .mko file's namespaced functions available. It does not connect that file to the whole script like using does. The local file only does work when you call one of its functions through its namespace.

Try this code
# mathlib.mko — the helper file
namespace MathLib;

fn square(x) {
    return x * x;
}

# main.mko — the file you run
use "mathlib.mko";

main() {
    # The used file has not done any work yet

    # The file said namespace MathLib, so call MathLib.square
    # MathLib only does its job when this line talks to it
    print MathLib.square(8);
}

use is for local files. The file must declare namespace Name;. Its functions wait until your code calls Name.function(...).

4

mylib pulls from GitHub

mylib means a library pulled from GitHub. MAKO downloads it and keeps a cached copy, then connects it to the script with using. Replace mylib, User, Repo, and MyLib with the real library's names.

Try this code
# Download the library once, cache it, and turn it on
using mylib from "github:User/Repo";

main() {
    # Use the namespace declared by that library's index.mko file
    print MyLib.hello("MAKO");
}

mylib is the GitHub package name after using. MyLib is the namespace inside its index.mko and is the name you talk to in code.

5

Pin a library to a version

Without a pin, a library is downloaded once and never changes on its own — but a fresh computer, or running mko cache clear, re-downloads whatever the library's default branch currently is, which may not match what you tested with. Add @ and a tag, branch, or commit to lock a library to one exact version everywhere.

Try this code
# Locked to the v1.2.0 tag — every computer that runs this
# script gets exactly that version, not "whatever is newest"
using mylib from "github:User/Repo@v1.2.0";

mko list shows the pinned version and the exact commit downloaded. Run mko update mylib when you actually want to move to whatever the pin currently points at (or the newest commit, if there's no pin).

6

Make your own mylib

A GitHub package needs an index.mko file at the repository's top level. index.mko must declare a namespace. mako.json is optional for running the package, but adding it lets MAKO's package browser explain what your library does.

Try this code
# Your GitHub repository
mylib/
├── index.mko   # Required: the library code
└── mako.json   # Recommended: name and description

# index.mko
namespace MyLib;

fn hello(name) {
    return "Hello, {name}!";
}

# mako.json
{
  "name": "mylib",
  "description": "A tiny hello library",
  "version": "0.1.0",
  "usage": "using mylib from \"github:User/Repo\";"
}

Run mko search github:User/Repo to preview mako.json. Run mko list to see downloaded libraries and mko cache clear mylib to download a fresh copy next time.

7

ModuMAKO adds the environment

This is the final variation. ModuMAKO requires a script name and writes its environment after a colon. ModuNode means the script belongs to and runs through a Modularity node.

Try this code
# ModuMAKO requires the environment
# Read this as: NameHere lives inside a ModuNode
script "NameHere" : ModuNode;

Normal MAKO: script "Name"; is optional. ModuMAKO: script "Name" : ModuNode; is required.