From f69788264e12939670fef78c6f9ebc073505a0c6 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 3 Mar 2016 09:59:53 -0500 Subject: [PATCH 1/6] Update README.md --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index b556500d..9b81012e 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,16 @@ Rhai is an embedded scripting language for Rust. It is meant to be a safe drop- **Note:** Currently, it's pre-0.1, and is likely to change a bit before it stabilizes enough for a crates.io release. +Rhai's current feature set: + +* Straightforward integration with your application +* Fairly efficient (1 mil iterations in 0.75 sec on my 5 year old laptop) +* Low compile-time overhead (~4 secs for debug build, ~11 secs for release build) +* Simple, easy-to-use scripting language +* Support for overloaded functions +* No additional dependencies +* No unsafe code + ## Variables ```Rust @@ -18,17 +28,36 @@ var x = 3; if true { print("it's true!"); } +else { + print("It's false!"); +} ``` ```Rust var x = 10; while x > 0 { print(x); + if x == 5 { + break; + } + x = x - 1; } ``` ## Functions +Rhai supports defining functions in script: + +```Rust +fn add(x, y) { + return x + y; +} + +print(add(2, 3)) +``` + +Just like in Rust, you can also use an implicit return. + ```Rust fn add(x, y) { x + y @@ -37,6 +66,7 @@ fn add(x, y) { print(add(2, 3)) ``` + # Example 1: Hello world ```Rust From e4369723e48d0a58bffb03215ef712e08335d6f9 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 3 Mar 2016 10:00:29 -0500 Subject: [PATCH 2/6] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9b81012e..2989392d 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ Rhai is an embedded scripting language for Rust. It is meant to be a safe drop- # Features -**Note:** Currently, it's pre-0.1, and is likely to change a bit before it stabilizes enough for a crates.io release. - Rhai's current feature set: * Straightforward integration with your application @@ -16,6 +14,8 @@ Rhai's current feature set: * No additional dependencies * No unsafe code +***Note:** Currently, it's pre-0.1, and is likely to change a bit before it stabilizes enough for a crates.io release.* + ## Variables ```Rust From b2e5dc2efce4f5822b9462695038484c678c5933 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 3 Mar 2016 10:00:41 -0500 Subject: [PATCH 3/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2989392d..f149d3ff 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Rhai's current feature set: * No additional dependencies * No unsafe code -***Note:** Currently, it's pre-0.1, and is likely to change a bit before it stabilizes enough for a crates.io release.* +* **Note:** Currently, it's pre-0.1, and is likely to change a bit before it stabilizes enough for a crates.io release.* ## Variables From 3e009ea895849c61871d6928f49f6f820a2bab3e Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 3 Mar 2016 10:01:09 -0500 Subject: [PATCH 4/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f149d3ff..22c3b202 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Rhai's current feature set: * No additional dependencies * No unsafe code -* **Note:** Currently, it's pre-0.1, and is likely to change a bit before it stabilizes enough for a crates.io release.* +**Note:** Currently, it's pre-0.1, and is likely to change a bit before it stabilizes enough for a crates.io release.* ## Variables From 906ee14138505e8779fbb8da3374c2dd5627027b Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 3 Mar 2016 10:10:08 -0500 Subject: [PATCH 5/6] Update README.md --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 22c3b202..59ff8f1d 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,13 @@ # Rhai - embedded scripting for Rust -Rhai is an embedded scripting language for Rust. It is meant to be a safe drop-in for your own projects and doesn't use any additional dependencies, unsafe code, or APIs outside of the ones you provide in your program. This allows you to have rich control over the functionality exposed to the scripting context. - -# Features +Rhai is an embedded scripting language for Rust that gives you a safe and easy way to add scripting to your applications. Rhai's current feature set: -* Straightforward integration with your application +* Easy integration with Rust functions and data types * Fairly efficient (1 mil iterations in 0.75 sec on my 5 year old laptop) * Low compile-time overhead (~4 secs for debug build, ~11 secs for release build) -* Simple, easy-to-use scripting language +* Simple, easy-to-use language features * Support for overloaded functions * No additional dependencies * No unsafe code From 3e70879eae4ee95b72772554da5759a42a2199c5 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 3 Mar 2016 10:14:11 -0500 Subject: [PATCH 6/6] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 59ff8f1d..2f9ed56a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Rhai's current feature set: * Easy integration with Rust functions and data types * Fairly efficient (1 mil iterations in 0.75 sec on my 5 year old laptop) * Low compile-time overhead (~4 secs for debug build, ~11 secs for release build) -* Simple, easy-to-use language features +* Easy-to-use language based on JS+Rust * Support for overloaded functions * No additional dependencies * No unsafe code @@ -112,6 +112,8 @@ fn main() { } ``` +You can also see in this example how you can register multiple functions (or in this case multiple instances of the same function) to the same name in script. The scripting engine will handle looking up the correct function during function resolution. + # Example 4: Working with custom types and methods Here's an more complete example of working with Rust. First the example, then we'll break it into parts: