Add linkcheck, fix typos and expand.
This commit is contained in:
39
doc/src/rust/packages/builtin.md
Normal file
39
doc/src/rust/packages/builtin.md
Normal file
@@ -0,0 +1,39 @@
|
||||
Built-In Packages
|
||||
================
|
||||
|
||||
{{#include ../../links.md}}
|
||||
|
||||
`Engine::new` creates an [`Engine`] with the `StandardPackage` loaded.
|
||||
|
||||
`Engine::new_raw` creates an [`Engine`] with _no_ package loaded.
|
||||
|
||||
| Package | Description | In `Core` | In `Standard` |
|
||||
| ---------------------- | ------------------------------------------------------------------------------------------------------ | :-------: | :-----------: |
|
||||
| `ArithmeticPackage` | Arithmetic operators (e.g. `+`, `-`, `*`, `/`) for numeric types that are not built in (e.g. `u16`) | Yes | Yes |
|
||||
| `BasicIteratorPackage` | Numeric ranges (e.g. `range(1, 10)`) | Yes | Yes |
|
||||
| `LogicPackage` | Logical and comparison operators (e.g. `==`, `>`) for numeric types that are not built in (e.g. `u16`) | Yes | Yes |
|
||||
| `BasicStringPackage` | Basic string functions (e.g. `print`, `debug`, `len`) that are not built in | Yes | Yes |
|
||||
| `BasicTimePackage` | Basic time functions (e.g. [timestamps]) | Yes | Yes |
|
||||
| `MoreStringPackage` | Additional string functions, including converting common types to string | No | Yes |
|
||||
| `BasicMathPackage` | Basic math functions (e.g. `sin`, `sqrt`) | No | Yes |
|
||||
| `BasicArrayPackage` | Basic [array] functions (not available under `no_index`) | No | Yes |
|
||||
| `BasicMapPackage` | Basic [object map] functions (not available under `no_object`) | No | Yes |
|
||||
| `EvalPackage` | Disable [`eval`] | No | No |
|
||||
| `CorePackage` | Basic essentials | Yes | Yes |
|
||||
| `StandardPackage` | Standard library (default for `Engine::new`) | No | Yes |
|
||||
|
||||
|
||||
Load the `CorePackage`
|
||||
---------------------
|
||||
|
||||
If only minimal functionalities is required, load the `CorePackage` instead:
|
||||
|
||||
```rust
|
||||
use rhai::Engine;
|
||||
use rhai::packages::{Package, CorePackage};
|
||||
|
||||
let mut engine = Engine::new_raw();
|
||||
let package = CorePackage::new();
|
||||
|
||||
engine.load_package(package.get());
|
||||
```
|
47
doc/src/rust/packages/create.md
Normal file
47
doc/src/rust/packages/create.md
Normal file
@@ -0,0 +1,47 @@
|
||||
Create a Custom Package
|
||||
======================
|
||||
|
||||
{{#include ../../links.md}}
|
||||
|
||||
Sometimes specific functionalities are needed, so custom packages can be created.
|
||||
|
||||
The macro `rhai::def_package!` is used to create a new custom package.
|
||||
|
||||
|
||||
Macro Parameters
|
||||
---------------
|
||||
|
||||
`def_package!(root:package_name:description, variable, block)`
|
||||
|
||||
* `root` - root namespace, usually `"rhai"`.
|
||||
|
||||
* `package_name` - name of the package, usually ending in `Package`.
|
||||
|
||||
* `description` - doc comment for the package.
|
||||
|
||||
* `variable` - a variable name holding a reference to the [module] that is to form the package.
|
||||
|
||||
* `block` - a code block that initializes the package.
|
||||
|
||||
```rust
|
||||
// Import necessary types and traits.
|
||||
use rhai::{
|
||||
def_package,
|
||||
packages::Package,
|
||||
packages::{ArithmeticPackage, BasicArrayPackage, BasicMapPackage, LogicPackage}
|
||||
};
|
||||
|
||||
// Define the package 'MyPackage'.
|
||||
def_package!(rhai:MyPackage:"My own personal super package", module, {
|
||||
// Aggregate existing packages simply by calling 'init' on each.
|
||||
ArithmeticPackage::init(module);
|
||||
LogicPackage::init(module);
|
||||
BasicArrayPackage::init(module);
|
||||
BasicMapPackage::init(module);
|
||||
|
||||
// Register additional Rust functions using the standard 'set_fn_XXX' module API.
|
||||
module.set_fn_1("foo", |s: ImmutableString| {
|
||||
Ok(foo(s.into_owned()))
|
||||
});
|
||||
});
|
||||
```
|
Reference in New Issue
Block a user