Move to lib style, move scripts into their own directory, start source examples

This commit is contained in:
jonathandturner
2016-03-03 10:55:28 -05:00
parent fbb5b72f24
commit fee3852979
13 changed files with 22 additions and 18 deletions

View File

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

View File

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

View File

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

View File

@@ -1,5 +0,0 @@
fn f(a, b, c, d, e, f) {
a - b * c - d * e - f
}
print(f(100, 5, 2, 9, 6, 32))

View File

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

View File

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

View File

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

View File

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

38
examples/rhai_runner.rs Normal file
View File

@@ -0,0 +1,38 @@
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::fmt::Display;
extern crate rhai;
use rhai::{Engine, FnRegister};
fn showit<T: Display>(x: &mut T) -> () {
println!("{}", x)
}
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");
&(showit as fn(x: &mut u64)->()).register(&mut engine, "print");
&(showit as fn(x: &mut f32)->()).register(&mut engine, "print");
&(showit as fn(x: &mut f64)->()).register(&mut engine, "print");
&(showit as fn(x: &mut bool)->()).register(&mut engine, "print");
&(showit as fn(x: &mut String)->()).register(&mut engine, "print");
if let Ok(mut f) = File::open(fname.clone()) {
let mut contents = String::new();
if let Ok(_) = f.read_to_string(&mut contents) {
match engine.eval(contents) {
Ok(_) => (),
Err(e) => {println!("Error: {:?}", e)}
}
}
}
}
}

View File

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

View File

@@ -1,4 +0,0 @@
print("hello");
print("this\nis \\ nice");
print("40 hex is \x40");
print("fun with unicode: \u2764 and \U0001F603");

View File

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