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 using modules here.
Methods
-
: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
true
if the module contains a member namedname
, otherwisefalse
. -
:member(name: str) -> any
-
Returns the value of the member
name
, or anerr
ifname
is 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.