merge
This commit is contained in:
commit
13c718c794
36
README.md
36
README.md
@ -1,10 +1,18 @@
|
|||||||
# Rhai - embedded scripting for Rust
|
# Rhai - embedded scripting for Rust
|
||||||
|
|
||||||
Rhai is an embedded scripting language for Rust. It is meant to be a safe drop-in for your own projects and doesn't use any additional dependencies, unsafe code, or APIs outside of the ones you provide in your program. This allows you to have rich control over the functionality exposed to the scripting context.
|
Rhai is an embedded scripting language for Rust that gives you a safe and easy way to add scripting to your applications.
|
||||||
|
|
||||||
# Features
|
Rhai's current feature set:
|
||||||
|
|
||||||
**Note:** Currently, it's pre-0.1, and is likely to change a bit before it stabilizes enough for a crates.io release.
|
* Easy integration with Rust functions and data types
|
||||||
|
* Fairly efficient (1 mil iterations in 0.75 sec on my 5 year old laptop)
|
||||||
|
* Low compile-time overhead (~4 secs for debug build, ~11 secs for release build)
|
||||||
|
* Easy-to-use language based on JS+Rust
|
||||||
|
* Support for overloaded functions
|
||||||
|
* No additional dependencies
|
||||||
|
* No unsafe code
|
||||||
|
|
||||||
|
**Note:** Currently, it's pre-0.1, and is likely to change a bit before it stabilizes enough for a crates.io release.*
|
||||||
|
|
||||||
## Variables
|
## Variables
|
||||||
|
|
||||||
@ -18,17 +26,36 @@ var x = 3;
|
|||||||
if true {
|
if true {
|
||||||
print("it's true!");
|
print("it's true!");
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
print("It's false!");
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```Rust
|
```Rust
|
||||||
var x = 10;
|
var x = 10;
|
||||||
while x > 0 {
|
while x > 0 {
|
||||||
print(x);
|
print(x);
|
||||||
|
if x == 5 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
x = x - 1;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
|
Rhai supports defining functions in script:
|
||||||
|
|
||||||
|
```Rust
|
||||||
|
fn add(x, y) {
|
||||||
|
return x + y;
|
||||||
|
}
|
||||||
|
|
||||||
|
print(add(2, 3))
|
||||||
|
```
|
||||||
|
|
||||||
|
Just like in Rust, you can also use an implicit return.
|
||||||
|
|
||||||
```Rust
|
```Rust
|
||||||
fn add(x, y) {
|
fn add(x, y) {
|
||||||
x + y
|
x + y
|
||||||
@ -37,6 +64,7 @@ fn add(x, y) {
|
|||||||
print(add(2, 3))
|
print(add(2, 3))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
# Example 1: Hello world
|
# Example 1: Hello world
|
||||||
|
|
||||||
```Rust
|
```Rust
|
||||||
@ -84,6 +112,8 @@ fn main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also see in this example how you can register multiple functions (or in this case multiple instances of the same function) to the same name in script. The scripting engine will handle looking up the correct function during function resolution.
|
||||||
|
|
||||||
# Example 4: Working with custom types and methods
|
# Example 4: Working with custom types and methods
|
||||||
|
|
||||||
Here's an more complete example of working with Rust. First the example, then we'll break it into parts:
|
Here's an more complete example of working with Rust. First the example, then we'll break it into parts:
|
||||||
|
Loading…
Reference in New Issue
Block a user