Skip to content

Commit

Permalink
Refine example scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Apr 9, 2021
1 parent 0f2e7e3 commit 2b1555c
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 16 deletions.
3 changes: 1 addition & 2 deletions scripts/array.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ print(x[1]);

x[1] = 5;

print("x[1] should be 5:");
print(x[1]);
print(`x[1] should be 5: ${x[1]}`);
1 change: 1 addition & 0 deletions scripts/assignment.rhai
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
print("x should be 78:");

let x = 78;

print(x);
2 changes: 1 addition & 1 deletion scripts/comments.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ let /* I am a spy in a variable declaration! */ x = 5;

/* look /* at /* that, /* multi-line */ comments */ can be */ nested */

/* surrounded by */ x // comments
/* surrounded by */ this_is_not_a_comment = true // comments
4 changes: 2 additions & 2 deletions scripts/function_decl1.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ fn bob() {
return 3;
}

print("bob() should be 3:");
let result = bob();

print(bob());
print(`bob() should be 3: ${result}`);
8 changes: 3 additions & 5 deletions scripts/function_decl2.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ fn addme(a, b) {
a + b; // notice that the last value is returned even if terminated by a semicolon
}

print("addme(a, 4) should be 46:");
let result = addme(a, 4);

print(addme(a, 4));
print(!addme(a, 4) should be 46: ${result}``);

print("a should still be 3:");

print(a); // should print 3 - 'a' is never changed
print(`a should still be 3: ${a}`); // should print 3 - 'a' is never changed
2 changes: 1 addition & 1 deletion scripts/if1.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ if a > b {
print(x); // should print 0
} else {
print("Oops! a == b");
}
}
2 changes: 2 additions & 0 deletions scripts/loop.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ loop {

if x <= 0 { break; }
}

export x as foo;
4 changes: 2 additions & 2 deletions scripts/mat_mul.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ fn new_mat(x, y) {

fn mat_gen(n) {
let m = new_mat(n, n);
let tmp = 1.0 / n.to_float() / n.to_float();
let tmp = 1.0 / n / n;

for i in range(0, n) {
for j in range(0, n) {
m[i][j] = tmp * (i.to_float() - j.to_float()) * (i.to_float() + j.to_float());
m[i][j] = tmp * (i - j) * (i + j);
}
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/module.rhai
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import "loop";
import "loop" as x;

print("Module test!");
print(`Module test! foo = ${x::foo}`);
1 change: 1 addition & 0 deletions scripts/op2.rhai
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
print("The result should be 182:");

let x = 12 + 34 * 5;

print(x);
1 change: 1 addition & 0 deletions scripts/op3.rhai
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
print("The result should be 230:");

let x = (12 + 34) * 5;

print(x);
2 changes: 1 addition & 1 deletion scripts/primes.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ print(`Run time = ${now.elapsed} seconds.`);

if total_primes_found != 78_498 {
print("The answer is WRONG! Should be 78,498!");
}
}
9 changes: 9 additions & 0 deletions scripts/string.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ made using multi-line literal

print(s);

// Interpolation
let s = `This is interpolation ${
let x = `within ${let y = "yet another level \
of interpolation!"; y} interpolation`;
x
} within literal string.`;

print(s);

print(">>> END <<<");

0 comments on commit 2b1555c

Please sign in to comment.