rhai/doc/src/rust/override.md

22 lines
536 B
Markdown
Raw Normal View History

2020-06-20 06:06:17 +02:00
Override a Built-in Function
===========================
{{#include ../links.md}}
Any similarly-named function defined in a script overrides any built-in or registered
native Rust function of the same name and number of parameters.
```rust
// Override the built-in function 'to_int'
fn to_int(num) {
print("Ha! Gotcha! " + num);
}
2020-07-26 04:07:40 +02:00
let x = (123).to_int();
print(x); // what happens?
2020-06-20 06:06:17 +02:00
```
A registered native Rust function, in turn, overrides any built-in function of the
same name, number and types of parameters.