From 760c13d36e5fb08946ca36996e6fe646cefb139c Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 1 Jul 2020 22:21:43 +0800 Subject: [PATCH] Fix features. --- Cargo.toml | 2 +- RELEASES.md | 10 ++++++++++ doc/src/context.json | 2 +- src/engine.rs | 16 ++++++++++++++-- src/packages/fn_basic.rs | 3 ++- src/parser.rs | 3 +++ tests/data_size.rs | 3 +++ tests/for.rs | 2 +- tests/functions.rs | 1 + 9 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2ffbd617..835fb830 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rhai" -version = "0.16.0" +version = "0.16.1" edition = "2018" authors = ["Jonathan Turner", "Lukáš Hozda", "Stephen Chung"] description = "Embedded scripting for Rust" diff --git a/RELEASES.md b/RELEASES.md index 6f38bb72..e60a0b1e 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,11 +1,21 @@ Rhai Release Notes ================== +Version 0.16.1 +============== + +Bug fix release to fix errors when compiling with features. + + Version 0.16.0 ============== The major new feature in this version is OOP - well, poor man's OOP, that is. +The `README` is officially transferred to [The Rhai Book](https://schungx.github.io/rhai). + +An online [Playground](https://alvinhochun.github.io/rhai-demo/) is available. + Breaking changes ---------------- diff --git a/doc/src/context.json b/doc/src/context.json index 6da8d6bb..2cc332fb 100644 --- a/doc/src/context.json +++ b/doc/src/context.json @@ -1,5 +1,5 @@ { - "version": "0.16.0", + "version": "0.16.1", "rootUrl": "", "rootUrlX": "/rhai" } \ No newline at end of file diff --git a/src/engine.rs b/src/engine.rs index 65c91735..96514f48 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -2407,7 +2407,13 @@ impl Engine { let mut maps = 0; arr.iter().for_each(|value| match value { - Dynamic(Union::Array(_)) | Dynamic(Union::Map(_)) => { + Dynamic(Union::Array(_)) => { + let (a, m, _) = calc_size(value); + arrays += a; + maps += m; + } + #[cfg(not(feature = "no_object"))] + Dynamic(Union::Map(_)) => { let (a, m, _) = calc_size(value); arrays += a; maps += m; @@ -2423,7 +2429,13 @@ impl Engine { let mut maps = 0; map.values().for_each(|value| match value { - Dynamic(Union::Array(_)) | Dynamic(Union::Map(_)) => { + #[cfg(not(feature = "no_index"))] + Dynamic(Union::Array(_)) => { + let (a, m, _) = calc_size(value); + arrays += a; + maps += m; + } + Dynamic(Union::Map(_)) => { let (a, m, _) = calc_size(value); arrays += a; maps += m; diff --git a/src/packages/fn_basic.rs b/src/packages/fn_basic.rs index 01807c9e..dde08fd5 100644 --- a/src/packages/fn_basic.rs +++ b/src/packages/fn_basic.rs @@ -3,6 +3,7 @@ use crate::fn_native::FnPtr; def_package!(crate:BasicFnPackage:"Basic Fn functions.", lib, { lib.set_fn_1_mut("name", |f: &mut FnPtr| Ok(f.get_fn_name().clone())); - lib.set_getter_fn("name", |f: &mut FnPtr| Ok(f.get_fn_name().clone())); + #[cfg(not(feature = "no_object"))] + lib.set_getter_fn("name", |f: &mut FnPtr| Ok(f.get_fn_name().clone())); }); diff --git a/src/parser.rs b/src/parser.rs index 906d99de..3ff3798f 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2194,6 +2194,7 @@ fn parse_let( } /// Parse an import statement. +#[cfg(not(feature = "no_module"))] fn parse_import( input: &mut TokenStream, state: &mut ParseState, @@ -2444,6 +2445,8 @@ fn parse_stmt( Token::Let => parse_let(input, state, Normal, settings.level_up()), Token::Const => parse_let(input, state, Constant, settings.level_up()), + + #[cfg(not(feature = "no_module"))] Token::Import => parse_import(input, state, settings.level_up()), #[cfg(not(feature = "no_module"))] diff --git a/tests/data_size.rs b/tests/data_size.rs index e073d443..33257cfd 100644 --- a/tests/data_size.rs +++ b/tests/data_size.rs @@ -35,6 +35,7 @@ fn test_max_string_size() -> Result<(), Box> { EvalAltResult::ErrorDataTooLarge(_, 10, 13, _) )); + #[cfg(not(feature = "no_object"))] assert!(matches!( *engine .eval::( @@ -92,6 +93,8 @@ fn test_max_array_size() -> Result<(), Box> { .expect_err("should error"), EvalAltResult::ErrorDataTooLarge(_, 10, 12, _) )); + + #[cfg(not(feature = "no_object"))] assert!(matches!( *engine .eval::( diff --git a/tests/for.rs b/tests/for.rs index 4f99c06f..e3b561d6 100644 --- a/tests/for.rs +++ b/tests/for.rs @@ -39,7 +39,7 @@ fn test_for_string() -> Result<(), Box> { let sum = 0; for ch in s { - sum += ch.to_int(); + sum += to_int(ch); } sum diff --git a/tests/functions.rs b/tests/functions.rs index 49789da4..ed3eeb73 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -52,6 +52,7 @@ fn test_functions() -> Result<(), Box> { } #[test] +#[cfg(not(feature = "no_object"))] fn test_function_pointers() -> Result<(), Box> { let engine = Engine::new();