Namespaces
Every symbol in Amethyst is put into a namespace for organization.
Syntax
The namespace statement denotes the default namespace that future symbols use if they don't have a namespace explicitly defined.
namespace example;
// Compiles to example:foo
void foo() { }
// Compiles to other:bar
void other:bar() { }
Multiple namespaces can be declared in the same file:
// Equivalent to the previous example
namespace example;
void foo() { }
namespace other;
void bar() { }
Directories
You can also declare a subdirectory:
// Compiles to example:folder/func
namespace example:folder;
void func() { }
The namespace and path of a function determines where to search for other functions or global variables when not using fully-qualified names. For example:
namespace example;
void func() {
// Yes, you can have dashes in function names
other-func();
}
void other-func() {
print("yay");
}
namespace example:sub;
void test() {
// Can use example:func implicitly
func();
}
namespace main;
#load
void main() {
// Omitting example causes Amethyst to search the main namespace
// for other-func which results in an error
example:other-func();
}
All symbols in the builtin and base minecraft namespace are available everywhere.
Using Statements
Namespaces can be "imported" with using statements. The path must be fully qualified and cannot omit already-imported namespaces.
using minecraft:math;
using math; // Imports symbols in the "math" namespace, not "minecraft:math"
Amethyst does not throw an error if the namespace does not exist. By default, minecraft and builtin are already imported.