Move script optimization into separate section.

This commit is contained in:
Stephen Chung
2020-10-06 22:35:27 +08:00
parent ae1157a140
commit 762072685d
9 changed files with 65 additions and 35 deletions

View File

@@ -10,9 +10,12 @@ Create a Module from an AST
A _module_ can be created from a single script (or pre-compiled [`AST`]) containing global variables,
functions and sub-modules via the `Module::eval_ast_as_new` method.
See the section on [_Exporting Variables, Functions and Sub-Modules_][`export`] for details on how to prepare
a Rhai script for this purpose as well as to control which functions/variables to export.
When given an [`AST`], it is first evaluated, then the following items are exposed as members of the new module:
* Global variables - essentially all variables that remain in the [`Scope`] at the end of a script run - that are exported. Variables not exported (via the `export` statement) remain hidden.
* Global variables - all variables exported via the `export` statement (those not exported remain hidden).
* Functions not specifically marked `private`.

View File

@@ -0,0 +1,14 @@
Modules
=======
{{#include ../../links.md}}
Rhai allows organizing code (functions, both Rust-based or script-based, and variables) into _modules_.
Modules can be disabled via the [`no_module`] feature.
A module is of the type `Module` and holds a collection of functions, variables, iterators and sub-modules.
It may be created entirely from Rust functions, or it may encapsulate a Rhai script together with the functions
and variables defined by that script.
Other scripts can then load this module and use the functions and variables exported
as if they were defined inside the same script.

View File

@@ -5,6 +5,8 @@ Module Resolvers
When encountering an [`import`] statement, Rhai attempts to _resolve_ the module based on the path string.
See the section on [_Importing Modules_][`import`] for more details.
_Module Resolvers_ are service types that implement the [`ModuleResolver`][traits] trait.