Skip to content

Commit

Permalink
Merge pull request #128 from schungx/master
Browse files Browse the repository at this point in the history
Reentrant Engine, Rust anonymous functions, `in` expression, timestamps, bug fixes
  • Loading branch information
schungx committed Apr 13, 2020
2 parents 66a4956 + 50a0f14 commit 2330dcb
Show file tree
Hide file tree
Showing 55 changed files with 2,465 additions and 1,519 deletions.
20 changes: 11 additions & 9 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rhai"
version = "0.11.0"
version = "0.12.0"
edition = "2018"
authors = ["Jonathan Turner", "Lukáš Hozda", "Stephen Chung"]
description = "Embedded scripting for Rust"
Expand All @@ -17,48 +17,50 @@ keywords = [ "scripting" ]
categories = [ "no-std", "embedded", "parser-implementations" ]

[dependencies]
num-traits = "*"
num-traits = { version = "0.2.11", default-features = false }

[features]
#default = ["no_function", "no_index", "no_object", "no_float", "only_i32", "no_stdlib", "unchecked", "no_optimize", "sync"]
#default = ["no_stdlib", "no_function", "no_index", "no_object", "no_float", "only_i32", "unchecked", "no_optimize", "sync"]
default = []
unchecked = [] # unchecked arithmetic
no_stdlib = [] # no standard library of utility functions
no_index = [] # no arrays and indexing
no_float = [] # no floating-point
no_function = [] # no script-defined functions
no_object = [] # no custom objects
no_optimize = [] # no script optimizer
optimize_full = [] # set optimization level to Full (default is Simple) - this is a feature used only to simplify testing
only_i32 = [] # set INT=i32 (useful for 32-bit systems)
only_i64 = [] # set INT=i64 (default) and disable support for all other integer types
sync = [] # restrict to only types that implement Send + Sync

# compiling for no-std
no_std = [ "num-traits/libm", "hashbrown", "core-error", "libm" ]

# other developer features
no_stdlib = [] # do not register the standard library
optimize_full = [] # set optimization level to Full (default is Simple) - this is a feature used only to simplify testing

[profile.release]
lto = "fat"
codegen-units = 1
#opt-level = "z" # optimize for size
#panic = 'abort' # remove stack backtrace for no-std

[dependencies.libm]
version = "*"
version = "0.2.1"
optional = true

[dependencies.core-error]
version = "*"
version = "0.0.0"
features = ["alloc"]
optional = true

[dependencies.hashbrown]
version = "*"
version = "0.7.1"
default-features = false
features = ["ahash", "nightly", "inline-more"]
optional = true

[dependencies.ahash]
version = "*"
version = "0.3.2"
default-features = false
optional = true
495 changes: 370 additions & 125 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/hello.rs
@@ -1,7 +1,7 @@
use rhai::{Engine, EvalAltResult, INT};

fn main() -> Result<(), EvalAltResult> {
let mut engine = Engine::new();
let engine = Engine::new();

let result = engine.eval::<INT>("40 + 2")?;

Expand Down
2 changes: 1 addition & 1 deletion examples/no_std.rs
Expand Up @@ -3,7 +3,7 @@
use rhai::{Engine, EvalAltResult, INT};

fn main() -> Result<(), EvalAltResult> {
let mut engine = Engine::new();
let engine = Engine::new();

let result = engine.eval::<INT>("40 + 2")?;

Expand Down
4 changes: 1 addition & 3 deletions examples/repl.rs
Expand Up @@ -145,9 +145,7 @@ fn main() {

#[cfg(not(feature = "no_optimize"))]
{
engine.set_optimization_level(OptimizationLevel::Full);
ast = engine.optimize_ast(&scope, r);
engine.set_optimization_level(OptimizationLevel::None);
ast = engine.optimize_ast(&scope, r, OptimizationLevel::Full);
}

#[cfg(feature = "no_optimize")]
Expand Down
2 changes: 1 addition & 1 deletion examples/reuse_scope.rs
@@ -1,7 +1,7 @@
use rhai::{Engine, EvalAltResult, Scope, INT};

fn main() -> Result<(), EvalAltResult> {
let mut engine = Engine::new();
let engine = Engine::new();
let mut scope = Scope::new();

engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5")?;
Expand Down
3 changes: 3 additions & 0 deletions scripts/primes.rhai
@@ -1,5 +1,7 @@
// This script uses the Sieve of Eratosthenes to calculate prime numbers.

let now = timestamp();

const MAX_NUMBER_TO_CHECK = 10_000; // 1229 primes <= 10000

let prime_mask = [];
Expand All @@ -24,3 +26,4 @@ for p in range(2, MAX_NUMBER_TO_CHECK) {
}

print("Total " + total_primes_found + " primes.");
print("Run time = " + now.elapsed() + " seconds.");
3 changes: 2 additions & 1 deletion scripts/speed_test.rhai
@@ -1,6 +1,7 @@
// This script runs 1 million iterations
// to test the speed of the scripting engine.

let now = timestamp();
let x = 1_000_000;

print("Ready... Go!");
Expand All @@ -9,4 +10,4 @@ while x > 0 {
x = x - 1;
}

print("Finished.");
print("Finished. Run time = " + now.elapsed() + " seconds.");

0 comments on commit 2330dcb

Please sign in to comment.