Modules
A module object, module, is created when you import a Pyro source file using an import statement, e.g.
import std::math; assert $is_module(math);
A module object can also be created by executing a string of source code using the $exec() function, e.g.
var mod = $exec("pub var foo = 1 + 2;"); assert $is_module(mod); assert mod::foo == 3;
A module contains members — its global variables, functions, and classes — which can be accessed using the member operator, ::.
A module object also has methods of its own, which can be accessed using the method operator, :, e.g.
assert mod:has_member("foo"); assert mod:member("foo") == 3; var globals = mod:globals(); assert globals["foo"] == 3;
You can learn more about importing modules here.
Methods
-
:all_members() -> iter[str] -
Returns an iterator over the module's member names as strings. Includes both public and private members.
-
:globals() -> map[str, any] -
Returns a new map containing a copy of the module's public members, indexed by name.
-
:has_member(name: str) -> bool -
Returns
trueif the module contains a member namedname, otherwisefalse.The member can be public or private.
-
:member(name: str) -> any -
Returns the value of the member
name, or anerrifnameis not defined.Allows access to both public and private members.
-
:members() -> iter[str] -
Returns an iterator over the module's public member names as strings.