Modules

// Module is an extension, which is a combination of between language and implementation.

Using module

To use a module, just with a use keyword.

use math

The above statement will load math module and math identifier will be a local variable. By default, math module return a map that contains static functions and properties.

puts math.abs(-5)    // 5

Alias

Using module with another name, or many module have special name, alias is a great way to deal with them.

use m as "math"
use my_math as "this-is-my-custom-math"

Declared variables of use statement are immutable, so you cannot assign value to them.

You should declare using of modules in top of your code.

Creating module

We have two ways to create a module:

1. By code

Create a new file named my-module.m.aup

my-module.m.aup
func add(a, b) {
    return a + b
}

return { add }

And use it

main.aup
use my_mod = "my-module"
puts my_mod.add(4, 5)    // 9

Run with aup

$ aup main.aup

If module not found, the compiler will stop and show error.

Pass option -m path/to/module to tell compiler finds module.

2. With C++

It is not strange at all, because aup is written in C++ 😄

// todo, we'll provide it soon

Last updated