Refine docs.
This commit is contained in:
@@ -6,8 +6,8 @@ Dynamic Values
|
||||
A `Dynamic` value can be _any_ type. However, under [`sync`], all types must be `Send + Sync`.
|
||||
|
||||
|
||||
Use [`type_of()`] to Get Value Type
|
||||
----------------------------------
|
||||
Use `type_of()` to Get Value Type
|
||||
--------------------------------
|
||||
|
||||
Because [`type_of()`] a `Dynamic` value returns the type of the actual value,
|
||||
it is usually used to perform type-specific actions based on the actual value's type.
|
||||
|
@@ -65,17 +65,15 @@ disable `eval` by overloading it, probably with something that throws.
|
||||
```rust
|
||||
fn eval(script) { throw "eval is evil! I refuse to run " + script }
|
||||
|
||||
let x = eval("40 + 2"); // 'eval' here throws "eval is evil! I refuse to run 40 + 2"
|
||||
let x = eval("40 + 2"); // throws "eval is evil! I refuse to run 40 + 2"
|
||||
```
|
||||
|
||||
Or overload it from Rust:
|
||||
|
||||
```rust
|
||||
fn alt_eval(script: String) -> Result<(), Box<EvalAltResult>> {
|
||||
engine.register_result_fn("eval", |script: String| -> Result<(), Box<EvalAltResult>> {
|
||||
Err(format!("eval is evil! I refuse to run {}", script).into())
|
||||
}
|
||||
|
||||
engine.register_result_fn("eval", alt_eval);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
|
@@ -9,6 +9,9 @@ is provided by the `for` ... `in` loop.
|
||||
Like C, `continue` can be used to skip to the next iteration, by-passing all following statements;
|
||||
`break` can be used to break out of the loop unconditionally.
|
||||
|
||||
To loop through a number sequence (with or without steps), use the `range` function to
|
||||
return a numeric iterator.
|
||||
|
||||
```rust
|
||||
// Iterate through string, yielding characters
|
||||
let s = "hello, world!";
|
||||
|
@@ -20,14 +20,15 @@ Global Variables
|
||||
|
||||
The `export` statement, which can only be at global level, exposes selected variables as members of a module.
|
||||
|
||||
Variables not exported are _private_ and hidden to the outside.
|
||||
Variables not exported are _private_ and hidden. They are merely used to initialize the module,
|
||||
but cannot be accessed from outside.
|
||||
|
||||
Everything exported from a module is **constant** (**read-only**).
|
||||
|
||||
```rust
|
||||
// This is a module script.
|
||||
|
||||
let private = 123; // variable not exported - default hidden
|
||||
let hidden = 123; // variable not exported - default hidden
|
||||
let x = 42; // this will be exported below
|
||||
|
||||
export x; // the variable 'x' is exported under its own name
|
||||
@@ -43,9 +44,6 @@ export x as answer; // the variable 'x' is exported under the alias 'answer'
|
||||
}
|
||||
```
|
||||
|
||||
[`private`] variables are used to initialize the module.
|
||||
They cannot be used apart from this.
|
||||
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
@@ -10,7 +10,7 @@ Unary Operators
|
||||
|
||||
| Operator | Description |
|
||||
| -------- | ----------- |
|
||||
| `+` | Plus |
|
||||
| `+` | Positive |
|
||||
| `-` | Negative |
|
||||
|
||||
```rust
|
||||
|
@@ -1,5 +1,5 @@
|
||||
`timestamp`'s
|
||||
=============
|
||||
`timestamp`
|
||||
===========
|
||||
|
||||
{{#include ../links.md}}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
`type_of`
|
||||
=========
|
||||
`type_of()`
|
||||
===========
|
||||
|
||||
{{#include ../links.md}}
|
||||
|
||||
|
Reference in New Issue
Block a user