Add note on &T
parameters.
This commit is contained in:
parent
efe964f009
commit
b8b1efd241
@ -36,6 +36,8 @@ update(array[0]); // <- 'array[0]' is an expression returning a calculated val
|
|||||||
array[0].update(); // <- call in method-call style will update 'a'
|
array[0].update(); // <- call in method-call style will update 'a'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**IMPORTANT: Rhai does NOT support normal references (i.e. `&T`) as parameters.**
|
||||||
|
|
||||||
|
|
||||||
Number of Parameters
|
Number of Parameters
|
||||||
--------------------
|
--------------------
|
||||||
@ -51,8 +53,8 @@ The following table illustrates the differences:
|
|||||||
| Rhai script | _n_ | `this` | `fn method(x, y) {}` |
|
| Rhai script | _n_ | `this` | `fn method(x, y) {}` |
|
||||||
|
|
||||||
|
|
||||||
`&mut` is Efficient (Except for `ImmutableString`)
|
`&mut` is Efficient, Except for `ImmutableString`
|
||||||
------------------------------------------------
|
-----------------------------------------------
|
||||||
|
|
||||||
Using a `&mut` first parameter is highly encouraged when using types that are expensive to clone,
|
Using a `&mut` first parameter is highly encouraged when using types that are expensive to clone,
|
||||||
even when the intention is not to mutate that argument, because it avoids cloning that argument value.
|
even when the intention is not to mutate that argument, because it avoids cloning that argument value.
|
||||||
|
@ -83,6 +83,8 @@ engine
|
|||||||
***Note**: Rhai follows the convention that methods of custom types take a `&mut` first parameter
|
***Note**: Rhai follows the convention that methods of custom types take a `&mut` first parameter
|
||||||
so that invoking methods can update the types. All other parameters in Rhai are passed by value (i.e. clones).*
|
so that invoking methods can update the types. All other parameters in Rhai are passed by value (i.e. clones).*
|
||||||
|
|
||||||
|
**IMPORTANT: Rhai does NOT support normal references (i.e. `&T`) as parameters.**
|
||||||
|
|
||||||
Use the Custom Type in Scripts
|
Use the Custom Type in Scripts
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
@ -125,8 +127,8 @@ Under [`no_object`], however, the _method_ style of function calls
|
|||||||
let result = engine.eval::<()>("let x = [1, 2, 3]; x.clear()")?;
|
let result = engine.eval::<()>("let x = [1, 2, 3]; x.clear()")?;
|
||||||
```
|
```
|
||||||
|
|
||||||
[`type_of()`]
|
`type_of()` a Custom Type
|
||||||
-------------
|
-------------------------
|
||||||
|
|
||||||
[`type_of()`] works fine with custom types and returns the name of the type.
|
[`type_of()`] works fine with custom types and returns the name of the type.
|
||||||
|
|
||||||
|
@ -42,3 +42,5 @@ let result = engine.eval::<String>(r#"let a = new_ts(); a.xyz = "42"; a.xyz"#)?;
|
|||||||
|
|
||||||
println!("Answer: {}", result); // prints 42
|
println!("Answer: {}", result); // prints 42
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**IMPORTANT: Rhai does NOT support normal references (i.e. `&T`) as parameters.**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user