Update README.md
This commit is contained in:
parent
fbb5b72f24
commit
f69788264e
30
README.md
30
README.md
@ -6,6 +6,16 @@ Rhai is an embedded scripting language for Rust. It is meant to be a safe drop-
|
|||||||
|
|
||||||
**Note:** Currently, it's pre-0.1, and is likely to change a bit before it stabilizes enough for a crates.io release.
|
**Note:** Currently, it's pre-0.1, and is likely to change a bit before it stabilizes enough for a crates.io release.
|
||||||
|
|
||||||
|
Rhai's current feature set:
|
||||||
|
|
||||||
|
* Straightforward integration with your application
|
||||||
|
* 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)
|
||||||
|
* Simple, easy-to-use scripting language
|
||||||
|
* Support for overloaded functions
|
||||||
|
* No additional dependencies
|
||||||
|
* No unsafe code
|
||||||
|
|
||||||
## Variables
|
## Variables
|
||||||
|
|
||||||
```Rust
|
```Rust
|
||||||
@ -18,17 +28,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 +66,7 @@ fn add(x, y) {
|
|||||||
print(add(2, 3))
|
print(add(2, 3))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
# Example 1: Hello world
|
# Example 1: Hello world
|
||||||
|
|
||||||
```Rust
|
```Rust
|
||||||
|
Loading…
x
Reference in New Issue
Block a user