Modules

Rhai allows organizing functionalities (functions, both Rust-based and scripted, and variables) into independent modules.

A module has the type rhai::Module and holds a collection of functions, variables, type iterators and sub-modules.

It may contain entirely Rust functions, or it may encapsulate a Rhai script together with all the functions and variables defined by that script.

Other scripts then load this module and use the functions and variables exported.

Alternatively, modules can be registered directly into an Engine and made available to scripts, either globally or under individual static module namespaces.

Modules can be disabled via the no_module feature.

Usage Patterns

UsageAPILookupSub-modules?Variables?
Global moduleEngine:: register_global_modulesimple nameignoredyes
Static moduleEngine:: register_static_modulenamespace-qualified nameyesyes
Dynamic moduleimport statementnamespace-qualified nameyesyes