Overview
A MUFL library is a collection of functions, variables, types, and modules that offer useful features to other libraries or applications.
Library source files use the .mlib extension. The older .mm extension is deprecated: it is still accepted, so existing .mm libraries keep working, but new libraries should use .mlib. (Application source files use the .mu extension.) A single library must not be supplied as both a .mm and a .mlib file of the same name and version; doing so is a compile error.
Here is an example of a MUFL library:
// FILE: coordinates.mlib
library coordinates {
metadef radial: ...
metadef carthesian: ...
fn radial_to_cartesian (c:radial) -> cartesian { ... }
...
}
The MUFL compiler loads libraries similarly to how include works in C++. Specify the loads keyword in your code to instruct the compiler to load a library. For example:
// FILE: shapes.mlib
library shapes loads library coordinates { // loads coordinates.mlib
metadef cube: ($position->coordinates::radial, ... ).
...
}
As described in the section on name visibility, to gain access to the names the library exports, a library must be loaded explicitly. Libraries that are recursively loaded by explicitly-loaded libraries are not visible.
Libraries may contain modules. For example:
// FILE: A.mlib
library A {
module Hello {
value = 1.
}
fn print_hello (_) {
_print ::A::Hello::value "\n". // prints "1"
}
print_hello().
}
Prints:
1