A module is a Pyro file loaded as a library. Modules are loaded using the
Assume we have a file called
math.pyro containing math functions:
import math; var foo = math::abs(-1);
Use the member access operator
:: to access a module's top-level variables, functions, and classes.
Modules can contain submodules. Assume we have a directory called
math containing a file called
import math::trig; var foo = trig::cos(1);
The top-level module
math can live alongside the directory that contains its submodules:
root/ |-- math.pyro |-- math/ |-- trig.pyro
Alternatively, it can live inside the
math directory in a file called
root/ |-- math/ |-- self.pyro |-- trig.pyro
Finally, the top-level
math module can be empty and simply function as a container for its submodules:
root/ |-- math/ |-- trig.pyro
Submodules can contain submodules of their own — there's no hard limit to how deep the nesting can go.
You can import a module under an alias using an
import ... as ... statement:
import math as alias; var foo = alias::abs(-1);
Submodules can similarly be aliased:
import math::trig as alias; var foo = alias::cos(1);
The standard library's
$std::pyro::import_roots vector contains the list of root directories that Pyro checks when attempting to import a module.
Currently, if Pyro is executing a script it checks the parent directory containing that script. If the REPL is executing it checks the current working directory.
You can add or remove entries from the
import_roots vector to customize Pyro's default behaviour.