Skip to content

Commit

Permalink
Pretty up scripts with print.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed May 2, 2020
1 parent fc99b98 commit fc66a7e
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 13 deletions.
6 changes: 4 additions & 2 deletions scripts/array.rhai
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
let x = [1, 2, 3];

print(x[1]); // prints 2
print("x[1] should be 2:");
print(x[1]);

x[1] = 5;

print(x[1]); // prints 5
print("x[1] should be 5:");
print(x[1]);
2 changes: 2 additions & 0 deletions scripts/assignment.rhai
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
print("x should be 78:");

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

/* I am a simple
multi-line comment */
multi-line
comment */

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

Expand Down
2 changes: 1 addition & 1 deletion scripts/for1.rhai
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This script runs for-loops

let arr = [1,2,3,4];
let arr = [1, 2, 3, 4];

for a in arr {
for b in [10, 20] {
Expand Down
4 changes: 3 additions & 1 deletion scripts/function_decl1.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ fn bob() {
return 3;
}

print(bob()); // should print 3
print("bob() should be 3:");

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

print(addme(a, 4)); // should print 46
print("addme(a, 4) should be 46:");

print(addme(a, 4));

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

print(a); // should print 3 - 'a' is never changed
4 changes: 3 additions & 1 deletion scripts/function_decl3.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ fn f(a, b, c, d, e, f) {
a - b * c - d * e - f
}

print(f(100, 5, 2, 9, 6, 32)); // should print 4
print("f() call should be 4:");

print(f(100, 5, 2, 9, 6, 32));
6 changes: 3 additions & 3 deletions scripts/if1.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ let b = 123;
let x = 999;

if a > b {
print("a > b");
print("Oops! a > b");
} else if a < b {
print("a < b");
print("a < b, x should be 0");

let x = 0; // this 'x' shadows the global 'x'
print(x); // should print 0
} else {
print("a == b");
print("Oops! a == b");
}
4 changes: 3 additions & 1 deletion scripts/op1.rhai
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
print(34 + 12); // should be 46
print("The result should be 46:");

print(34 + 12);
4 changes: 3 additions & 1 deletion scripts/op2.rhai
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
print("The result should be 182:");

let x = 12 + 34 * 5;
print(x); // should be 182
print(x);
4 changes: 3 additions & 1 deletion scripts/op3.rhai
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
print("The result should be 230:");

let x = (12 + 34) * 5;
print(x); // should be 230
print(x);

0 comments on commit fc66a7e

Please sign in to comment.