Refine docs and API.
This commit is contained in:
@@ -104,9 +104,10 @@ The Rhai Scripting Language
|
||||
4. [Side-Effect Considerations](engine/optimize/side-effects.md)
|
||||
5. [Volatility Considerations](engine/optimize/volatility.md)
|
||||
6. [Subtle Semantic Changes](engine/optimize/semantics.md)
|
||||
4. [Disable Keywords and/or Operators](engine/disable.md)
|
||||
5. [Custom Operators](engine/custom-op.md)
|
||||
6. [Eval Statement](language/eval.md)
|
||||
4. [Low-Level API](rust/register-raw.md)
|
||||
5. [Disable Keywords and/or Operators](engine/disable.md)
|
||||
6. [Custom Operators](engine/custom-op.md)
|
||||
7. [Eval Statement](language/eval.md)
|
||||
9. [Appendix](appendix/index.md)
|
||||
1. [Keywords](appendix/keywords.md)
|
||||
2. [Operators](appendix/operators.md)
|
||||
|
@@ -15,7 +15,7 @@ Operators
|
||||
| `<<` | Left bit-shift | Yes | Left |
|
||||
| `&` | Bit-wise _And_, Boolean _And_ | Yes | Left |
|
||||
| <code>\|</code> | Bit-wise _Or_, Boolean _Or_ | Yes | Left |
|
||||
| `^` | Bit-wise _Xor_ | Yes | Left |
|
||||
| `^` | Bit-wise _Xor_, Boolean _Xor_ | Yes | Left |
|
||||
| `==` | Equals to | Yes | Left |
|
||||
| `~=` | Not equals to | Yes | Left |
|
||||
| `>` | Greater than | Yes | Left |
|
||||
|
@@ -18,8 +18,8 @@ use rhai::{Engine, RegisterFn};
|
||||
let mut engine = Engine::new();
|
||||
|
||||
// Register a custom operator called 'foo' and give it
|
||||
// a precedence of 140 (i.e. between +|- and *|/)
|
||||
engine.register_custom_operator("foo", 140).unwrap();
|
||||
// a precedence of 160 (i.e. between +|- and *|/)
|
||||
engine.register_custom_operator("foo", 160).unwrap();
|
||||
|
||||
// Register the implementation of the customer operator as a function
|
||||
engine.register_fn("foo", |x: i64, y: i64| (x * y) - (x + y));
|
||||
@@ -49,7 +49,7 @@ Therefore, the following are equivalent (assuming `foo` has been registered as a
|
||||
A script using custom operators can always be pre-processed, via a pre-processor application,
|
||||
into a syntax that uses the corresponding function calls.
|
||||
|
||||
Using `Engine::register_custom_operator` merely enables a convenient short-cut.
|
||||
Using `Engine::register_custom_operator` merely enables a convenient shortcut.
|
||||
|
||||
|
||||
Must Follow Variable Naming
|
||||
@@ -71,7 +71,7 @@ All custom operators must be _binary_ (i.e. they take two operands).
|
||||
_Unary_ custom operators are not supported.
|
||||
|
||||
```rust
|
||||
engine.register_custom_operator("foo", 140).unwrap();
|
||||
engine.register_custom_operator("foo", 160).unwrap();
|
||||
|
||||
engine.register_fn("foo", |x: i64| x * x);
|
||||
|
||||
@@ -91,12 +91,12 @@ The following _precedence table_ show the built-in precedence of standard Rhai o
|
||||
| Assignments | `=`, `+=`, `-=`, `*=`, `/=`, `~=`, `%=`,<br/>`<<=`, `>>=`, `&=`, <code>\|=</code>, `^=` | 0 |
|
||||
| Logic and bit masks | <code>\|\|</code>, <code>\|</code>, `^` | 30 |
|
||||
| Logic and bit masks | `&`, `&&` | 60 |
|
||||
| Comparisons | `==`, `!=`, `>`, `>=`, `<`, `<=` | 90 |
|
||||
| | `in` | 110 |
|
||||
| Arithmetic | `+`, `-` | 130 |
|
||||
| Arithmetic | `*`, `/`, `~` | 160 |
|
||||
| Bit-shifts | `<<`, `>>` | 190 |
|
||||
| Arithmetic | `%` | 210 |
|
||||
| Comparisons | `==`, `!=` | 90 |
|
||||
| Comparisons | `>`, `>=`, `<`, `<=` | 110 |
|
||||
| | `in` | 130 |
|
||||
| Arithmetic | `+`, `-` | 150 |
|
||||
| Arithmetic | `*`, `/`, `~`, `%` | 180 |
|
||||
| Bit-shifts | `<<`, `>>` | 210 |
|
||||
| Object | `.` _(binds to right)_ | 240 |
|
||||
| _Others_ | | 0 |
|
||||
|
||||
|
@@ -20,6 +20,7 @@
|
||||
[`Engine`]: {{rootUrl}}/engine/hello-world.md
|
||||
[traits]: {{rootUrl}}/rust/traits.md
|
||||
[`private`]: {{rootUrl}}/engine/call-fn.md
|
||||
[`call_fn`]: {{rootUrl}}/engine/call-fn.md
|
||||
[`Func`]: {{rootUrl}}/engine/func.md
|
||||
[`AST`]: {{rootUrl}}/engine/compile.md
|
||||
[`eval_expression`]: {{rootUrl}}/engine/expressions.md
|
||||
|
@@ -16,7 +16,7 @@ use rhai::RegisterResultFn; // use 'RegisterResultFn' trait
|
||||
fn safe_divide(x: i64, y: i64) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if y == 0 {
|
||||
// Return an error if y is zero
|
||||
Err("Division by zero!".into()) // short-cut to create Box<EvalAltResult::ErrorRuntime>
|
||||
Err("Division by zero!".into()) // shortcut to create Box<EvalAltResult::ErrorRuntime>
|
||||
} else {
|
||||
Ok((x / y).into()) // convert result into 'Dynamic'
|
||||
}
|
||||
|
Reference in New Issue
Block a user