Add a few examples
This commit is contained in:
parent
d8dd673459
commit
1320a35c81
2
examples/assignment.rhai
Normal file
2
examples/assignment.rhai
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
var x = 78
|
||||||
|
print(x)
|
5
examples/function_decl1.rhai
Normal file
5
examples/function_decl1.rhai
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
fn bob() {
|
||||||
|
3
|
||||||
|
}
|
||||||
|
|
||||||
|
print(bob())
|
5
examples/function_decl2.rhai
Normal file
5
examples/function_decl2.rhai
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
fn addme(a, b) {
|
||||||
|
a+b
|
||||||
|
}
|
||||||
|
|
||||||
|
print(addme(3, 4))
|
5
examples/if1.rhai
Normal file
5
examples/if1.rhai
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
var a = true;
|
||||||
|
if (a) {
|
||||||
|
var x = 56;
|
||||||
|
print(x);
|
||||||
|
}
|
1
examples/op1.rhai
Normal file
1
examples/op1.rhai
Normal file
@ -0,0 +1 @@
|
|||||||
|
print(34 + 12)
|
1
examples/op2.rhai
Normal file
1
examples/op2.rhai
Normal file
@ -0,0 +1 @@
|
|||||||
|
print(12 + 34 * 5)
|
1
examples/op3.rhai
Normal file
1
examples/op3.rhai
Normal file
@ -0,0 +1 @@
|
|||||||
|
print(0 + (12 + 34) * 5)
|
5
examples/speed_test.rhai
Normal file
5
examples/speed_test.rhai
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
var x = 1000000;
|
||||||
|
while x > 0 {
|
||||||
|
x = x - 1;
|
||||||
|
}
|
||||||
|
print(x);
|
6
examples/while.rhai
Normal file
6
examples/while.rhai
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
var x = 10;
|
||||||
|
|
||||||
|
while x > 0 {
|
||||||
|
print(x);
|
||||||
|
x = x - 1;
|
||||||
|
}
|
@ -12,11 +12,9 @@ use fn_register::FnRegister;
|
|||||||
mod parser;
|
mod parser;
|
||||||
|
|
||||||
// Todo (in no particular order):
|
// Todo (in no particular order):
|
||||||
// * Function in script
|
|
||||||
// * Doc some examples
|
// * Doc some examples
|
||||||
// * String constants
|
// * String constants
|
||||||
// * Remove empty box values?
|
// * Remove empty box values?
|
||||||
// * Refactor identifer to not require inlining of clone lookup in engine?
|
|
||||||
|
|
||||||
fn showit<T: Display>(x: &mut T) -> () {
|
fn showit<T: Display>(x: &mut T) -> () {
|
||||||
println!("{}", x)
|
println!("{}", x)
|
||||||
@ -25,7 +23,7 @@ fn showit<T: Display>(x: &mut T) -> () {
|
|||||||
fn main() {
|
fn main() {
|
||||||
for fname in env::args().skip(1) {
|
for fname in env::args().skip(1) {
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
|
|
||||||
&(showit as fn(x: &mut i32)->()).register(&mut engine, "print");
|
&(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 i64)->()).register(&mut engine, "print");
|
||||||
&(showit as fn(x: &mut u32)->()).register(&mut engine, "print");
|
&(showit as fn(x: &mut u32)->()).register(&mut engine, "print");
|
||||||
|
Loading…
Reference in New Issue
Block a user