Add a few examples

This commit is contained in:
jonathandturner 2016-03-01 21:36:46 -05:00
parent d8dd673459
commit 1320a35c81
10 changed files with 32 additions and 3 deletions

2
examples/assignment.rhai Normal file
View File

@ -0,0 +1,2 @@
var x = 78
print(x)

View File

@ -0,0 +1,5 @@
fn bob() {
3
}
print(bob())

View File

@ -0,0 +1,5 @@
fn addme(a, b) {
a+b
}
print(addme(3, 4))

5
examples/if1.rhai Normal file
View File

@ -0,0 +1,5 @@
var a = true;
if (a) {
var x = 56;
print(x);
}

1
examples/op1.rhai Normal file
View File

@ -0,0 +1 @@
print(34 + 12)

1
examples/op2.rhai Normal file
View File

@ -0,0 +1 @@
print(12 + 34 * 5)

1
examples/op3.rhai Normal file
View File

@ -0,0 +1 @@
print(0 + (12 + 34) * 5)

5
examples/speed_test.rhai Normal file
View File

@ -0,0 +1,5 @@
var x = 1000000;
while x > 0 {
x = x - 1;
}
print(x);

6
examples/while.rhai Normal file
View File

@ -0,0 +1,6 @@
var x = 10;
while x > 0 {
print(x);
x = x - 1;
}

View File

@ -12,11 +12,9 @@ use fn_register::FnRegister;
mod parser;
// Todo (in no particular order):
// * Function in script
// * Doc some examples
// * String constants
// * Remove empty box values?
// * Refactor identifer to not require inlining of clone lookup in engine?
fn showit<T: Display>(x: &mut T) -> () {
println!("{}", x)
@ -25,7 +23,7 @@ fn showit<T: Display>(x: &mut T) -> () {
fn main() {
for fname in env::args().skip(1) {
let mut engine = Engine::new();
&(showit as fn(x: &mut i32)->()).register(&mut engine, "print");
&(showit as fn(x: &mut i64)->()).register(&mut engine, "print");
&(showit as fn(x: &mut u32)->()).register(&mut engine, "print");