Update readme for release
This commit is contained in:
parent
1123b79d00
commit
02e67963e7
34
README.md
34
README.md
@ -12,7 +12,7 @@ Rhai's current feature set:
|
|||||||
* No additional dependencies
|
* No additional dependencies
|
||||||
* No unsafe code
|
* No unsafe code
|
||||||
|
|
||||||
**Note:** Currently, it's version 0.2.0, so the language and APIs may change before they stabilize.*
|
**Note:** Currently, it's version 0.3.0, so the language and APIs may change before they stabilize.*
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ You can install Rhai using crates by adding this line to your dependences:
|
|||||||
|
|
||||||
```
|
```
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rhai = "0.2.0"
|
rhai = "0.3.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Related
|
## Related
|
||||||
@ -40,7 +40,7 @@ use rhai::Engine;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
|
|
||||||
if let Ok(result) = engine.eval::<i32>("40 + 2") {
|
if let Ok(result) = engine.eval::<i64>("40 + 2") {
|
||||||
println!("Answer: {}", result); // prints 42
|
println!("Answer: {}", result); // prints 42
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ fn main() {
|
|||||||
You can also evaluate a script file:
|
You can also evaluate a script file:
|
||||||
|
|
||||||
```Rust
|
```Rust
|
||||||
if let Ok(result) = engine.eval_file::<i32>("hello_world.rhai") { ... }
|
if let Ok(result) = engine.eval_file::<i64>("hello_world.rhai") { ... }
|
||||||
```
|
```
|
||||||
|
|
||||||
# Working with functions
|
# Working with functions
|
||||||
@ -60,7 +60,7 @@ Rhai's scripting engine is very lightweight. It gets its ability from the funct
|
|||||||
extern crate rhai;
|
extern crate rhai;
|
||||||
use rhai::{Engine, FnRegister};
|
use rhai::{Engine, FnRegister};
|
||||||
|
|
||||||
fn add(x: i32, y: i32) -> i32 {
|
fn add(x: i64, y: i64) -> i64 {
|
||||||
x + y
|
x + y
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ fn main() {
|
|||||||
|
|
||||||
engine.register_fn("add", add);
|
engine.register_fn("add", add);
|
||||||
|
|
||||||
if let Ok(result) = engine.eval::<i32>("add(40, 2)") {
|
if let Ok(result) = engine.eval::<i64>("add(40, 2)") {
|
||||||
println!("Answer: {}", result); // prints 42
|
println!("Answer: {}", result); // prints 42
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ fn showit<T: Display>(x: &mut T) -> () {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
|
|
||||||
engine.register_fn("print", showit as fn(x: &mut i32)->());
|
engine.register_fn("print", showit as fn(x: &mut i64)->());
|
||||||
engine.register_fn("print", showit as fn(x: &mut bool)->());
|
engine.register_fn("print", showit as fn(x: &mut bool)->());
|
||||||
engine.register_fn("print", showit as fn(x: &mut String)->());
|
engine.register_fn("print", showit as fn(x: &mut String)->());
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ use rhai::{Engine, FnRegister};
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct TestStruct {
|
struct TestStruct {
|
||||||
x: i32
|
x: i64
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestStruct {
|
impl TestStruct {
|
||||||
@ -142,7 +142,7 @@ First, for each type we use with the engine, we need to be able to Clone. This
|
|||||||
```Rust
|
```Rust
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct TestStruct {
|
struct TestStruct {
|
||||||
x: i32
|
x: i64
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -188,15 +188,15 @@ For example:
|
|||||||
```Rust
|
```Rust
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct TestStruct {
|
struct TestStruct {
|
||||||
x: i32
|
x: i64
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestStruct {
|
impl TestStruct {
|
||||||
fn get_x(&mut self) -> i32 {
|
fn get_x(&mut self) -> i64 {
|
||||||
self.x
|
self.x
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_x(&mut self, new_x: i32) {
|
fn set_x(&mut self, new_x: i64) {
|
||||||
self.x = new_x;
|
self.x = new_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ engine.register_type::<TestStruct>();
|
|||||||
engine.register_get_set("x", TestStruct::get_x, TestStruct::set_x);
|
engine.register_get_set("x", TestStruct::get_x, TestStruct::set_x);
|
||||||
engine.register_fn("new_ts", TestStruct::new);
|
engine.register_fn("new_ts", TestStruct::new);
|
||||||
|
|
||||||
if let Ok(result) = engine.eval::<i32>("var a = new_ts(); a.x = 500; a.x") {
|
if let Ok(result) = engine.eval::<i64>("var a = new_ts(); a.x = 500; a.x") {
|
||||||
println!("result: {}", result);
|
println!("result: {}", result);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -233,7 +233,7 @@ fn main() {
|
|||||||
|
|
||||||
if let Ok(_) = engine.eval_with_scope::<()>(&mut scope, "var x = 4 + 5") { } else { assert!(false); }
|
if let Ok(_) = engine.eval_with_scope::<()>(&mut scope, "var x = 4 + 5") { } else { assert!(false); }
|
||||||
|
|
||||||
if let Ok(result) = engine.eval_with_scope::<i32>(&mut scope, "x") {
|
if let Ok(result) = engine.eval_with_scope::<i64>(&mut scope, "x") {
|
||||||
println!("result: {}", result);
|
println!("result: {}", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -315,4 +315,10 @@ a.x = 500;
|
|||||||
a.update();
|
a.update();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Strings and Chars
|
||||||
|
|
||||||
|
```Rust
|
||||||
|
var name = "Bob";
|
||||||
|
var middle_initial = 'C';
|
||||||
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user