Move to lib style, move scripts into their own directory, start source examples
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
var x = 78
|
||||
print(x)
|
@@ -1,5 +0,0 @@
|
||||
fn bob() {
|
||||
3
|
||||
}
|
||||
|
||||
print(bob())
|
@@ -1,5 +0,0 @@
|
||||
fn addme(a, b) {
|
||||
a+b
|
||||
}
|
||||
|
||||
print(addme(3, 4))
|
@@ -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))
|
@@ -1,5 +0,0 @@
|
||||
var a = true;
|
||||
if (a) {
|
||||
var x = 56;
|
||||
print(x);
|
||||
}
|
@@ -1 +0,0 @@
|
||||
print(34 + 12)
|
@@ -1 +0,0 @@
|
||||
print(12 + 34 * 5)
|
@@ -1 +0,0 @@
|
||||
print(0 + (12 + 34) * 5)
|
38
examples/rhai_runner.rs
Normal file
38
examples/rhai_runner.rs
Normal 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)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +0,0 @@
|
||||
var x = 1000000;
|
||||
while x > 0 {
|
||||
x = x - 1;
|
||||
}
|
||||
print(x);
|
@@ -1,4 +0,0 @@
|
||||
print("hello");
|
||||
print("this\nis \\ nice");
|
||||
print("40 hex is \x40");
|
||||
print("fun with unicode: \u2764 and \U0001F603");
|
@@ -1,6 +0,0 @@
|
||||
var x = 10;
|
||||
|
||||
while x > 0 {
|
||||
print(x);
|
||||
x = x - 1;
|
||||
}
|
Reference in New Issue
Block a user