'var' -> 'let' in README

This commit is contained in:
Lukáš Hozda 2017-10-02 18:46:35 +02:00
parent 6cadf25221
commit 92465e899e

View File

@ -131,7 +131,7 @@ fn main() {
engine.register_fn("update", TestStruct::update); engine.register_fn("update", TestStruct::update);
engine.register_fn("new_ts", TestStruct::new); engine.register_fn("new_ts", TestStruct::new);
if let Ok(result) = engine.eval::<TestStruct>("var x = new_ts(); x.update(); x") { if let Ok(result) = engine.eval::<TestStruct>("let x = new_ts(); x.update(); x") {
println!("result: {}", result.x); // prints 1001 println!("result: {}", result.x); // prints 1001
} }
} }
@ -174,7 +174,7 @@ engine.register_fn("new_ts", TestStruct::new);
Finally, we call our script. The script can see the function and method we registered earlier. We need to get the result back out from script land just as before, this time casting to our custom struct type. Finally, we call our script. The script can see the function and method we registered earlier. We need to get the result back out from script land just as before, this time casting to our custom struct type.
```Rust ```Rust
if let Ok(result) = engine.eval::<TestStruct>("var x = new_ts(); x.update(); x") { if let Ok(result) = engine.eval::<TestStruct>("let x = new_ts(); x.update(); x") {
println!("result: {}", result.x); // prints 1001 println!("result: {}", result.x); // prints 1001
} }
``` ```
@ -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::<i64>("var a = new_ts(); a.x = 500; a.x") { if let Ok(result) = engine.eval::<i64>("let a = new_ts(); a.x = 500; a.x") {
println!("result: {}", result); println!("result: {}", result);
} }
``` ```
@ -231,7 +231,7 @@ fn main() {
let mut engine = Engine::new(); let mut engine = Engine::new();
let mut scope: Scope = Vec::new(); let mut scope: Scope = Vec::new();
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, "let x = 4 + 5") { } else { assert!(false); }
if let Ok(result) = engine.eval_with_scope::<i64>(&mut scope, "x") { if let Ok(result) = engine.eval_with_scope::<i64>(&mut scope, "x") {
println!("result: {}", result); println!("result: {}", result);
@ -244,13 +244,13 @@ fn main() {
## Variables ## Variables
```Rust ```Rust
var x = 3; let x = 3;
``` ```
## Operators ## Operators
```Rust ```Rust
var x = (1 + 2) * (6 - 4) / 2; let x = (1 + 2) * (6 - 4) / 2;
``` ```
## If ## If
@ -265,7 +265,7 @@ else {
## While ## While
```Rust ```Rust
var x = 10; let x = 10;
while x > 0 { while x > 0 {
print(x); print(x);
if x == 5 { if x == 5 {
@ -301,7 +301,7 @@ print(add(2, 3))
You can create arrays of values, and then access them with numeric indices. You can create arrays of values, and then access them with numeric indices.
```Rust ```Rust
var y = [1, 2, 3]; let y = [1, 2, 3];
y[1] = 5; y[1] = 5;
print(y[1]); print(y[1]);
@ -310,7 +310,7 @@ print(y[1]);
## Members and methods ## Members and methods
```Rust ```Rust
var a = new_ts(); let a = new_ts();
a.x = 500; a.x = 500;
a.update(); a.update();
``` ```
@ -318,7 +318,7 @@ a.update();
## Strings and Chars ## Strings and Chars
```Rust ```Rust
var name = "Bob"; let name = "Bob";
var middle_initial = 'C'; let middle_initial = 'C';
``` ```