Add Dynamic::UNIT.

This commit is contained in:
Stephen Chung
2020-11-15 23:14:29 +08:00
parent 937b45a187
commit b75964e383
17 changed files with 34 additions and 26 deletions

View File

@@ -94,7 +94,7 @@ The following _precedence table_ shows the built-in precedence of standard Rhai
| ------------------- | :-------------------------------------------------------------------------------------: | :----------------: |
| Assignments | `=`, `+=`, `-=`, `*=`, `/=`, `~=`, `%=`,<br/>`<<=`, `>>=`, `&=`, <code>\|=</code>, `^=` | 0 |
| Logic and bit masks | <code>\|\|</code>, <code>\|</code>, `^` | 30 |
| Logic and bit masks | `&`, `&&` | 60 |
| Logic and bit masks | `&&`, `&` | 60 |
| Comparisons | `==`, `!=` | 90 |
| | `in` | 110 |
| Comparisons | `>`, `>=`, `<`, `<=` | 130 |

View File

@@ -216,7 +216,7 @@ fn implementation_func(
}
}
Ok(().into())
Ok(Dynamic::UNIT)
}
// Register the custom syntax (sample): exec |x| -> { x += 1 } while x < 0;

View File

@@ -118,7 +118,7 @@ engine.register_result_fn("bunny_set_speed", move |speed: i64|
return Err("Bunny is not yet going!".into());
}
Ok(().into())
Ok(Dynamic::UNIT)
);
```

View File

@@ -137,7 +137,7 @@ impl Handler {
// Default implementation of 'update' event handler
self.scope.set_value("state2", SomeType::new(42));
// Turn function-not-found into a success
Ok(().into())
Ok(Dynamic::UNIT)
}
_ => Err(err.into())
})

View File

@@ -131,7 +131,7 @@ pub mod bunny_api {
Err("Bunny is not yet going!".into())
} else {
b.borrow_mut().set_speed(speed);
Ok(().into())
Ok(Dynamic::UNIT)
}
}
pub fn turn_left(bunny: &mut SharedBunny) {

View File

@@ -10,7 +10,7 @@ packages to be used.
Packages typically contain Rust functions that are callable within a Rhai script.
All functions registered in a package is loaded under the _global namespace_
(i.e. they're available without module qualifiers).
(i.e. they're available without namespace qualifiers).
Once a package is created (e.g. via `Package::new`), it can be _shared_ (via `Package::get`)
among multiple instances of [`Engine`], even across threads (under [`sync`]).

View File

@@ -45,7 +45,7 @@ engine.register_raw_fn(
*x += y; // perform the action
Ok(().into()) // must be 'Result<Dynamic, Box<EvalAltResult>>'
Ok(Dynamic::UNIT) // must be 'Result<Dynamic, Box<EvalAltResult>>'
}
);

View File

@@ -37,7 +37,7 @@ wrapping this value.
The termination token is commonly used to provide information on the _reason_ or _source_
behind the termination decision.
If the termination token is not needed, simply return `Some(().into())` to terminate the script
If the termination token is not needed, simply return `Some(Dynamic::UNIT)` to terminate the script
run with [`()`] as the token.