diff --git a/examples/event_handler_js/main.rs b/examples/event_handler_js/main.rs index e47233d6..770127ce 100644 --- a/examples/event_handler_js/main.rs +++ b/examples/event_handler_js/main.rs @@ -1,5 +1,8 @@ //! Implementation of the Event Handler With State Pattern - JS Style -use rhai::{Dynamic, Engine, Map, Scope, AST}; +use rhai::{Dynamic, Engine, Scope, AST}; + +#[cfg(not(feature = "no_object"))] +use rhai::Map; use std::io::{stdin, stdout, Write}; @@ -18,18 +21,25 @@ fn print_scope(scope: &Scope) { .iter_raw() .enumerate() .for_each(|(i, (name, constant, value))| { + #[cfg(not(feature = "no_closure"))] + let value_is_shared = if value.is_shared() { " (shared)" } else { "" }; + #[cfg(feature = "no_closure")] + let value_is_shared = ""; + println!( "[{}] {}{}{} = {:?}", i + 1, if constant { "const " } else { "" }, name, - if value.is_shared() { " (shared)" } else { "" }, + value_is_shared, *value.read_lock::().unwrap(), ) }); println!(); } +#[cfg(not(feature = "no_function"))] +#[cfg(not(feature = "no_object"))] pub fn main() { println!("Events Handler Example - JS Style"); println!("=================================="); @@ -151,3 +161,8 @@ pub fn main() { println!("Bye!"); } + +#[cfg(any(feature = "no_function", feature = "no_object"))] +pub fn main() { + panic!("This example does not run under 'no_function' or 'no_object'.") +} diff --git a/examples/event_handler_main/main.rs b/examples/event_handler_main/main.rs index 5fddb1af..750d6742 100644 --- a/examples/event_handler_main/main.rs +++ b/examples/event_handler_main/main.rs @@ -17,18 +17,24 @@ fn print_scope(scope: &Scope) { .iter_raw() .enumerate() .for_each(|(i, (name, constant, value))| { + #[cfg(not(feature = "no_closure"))] + let value_is_shared = if value.is_shared() { " (shared)" } else { "" }; + #[cfg(feature = "no_closure")] + let value_is_shared = ""; + println!( "[{}] {}{}{} = {:?}", i + 1, if constant { "const " } else { "" }, name, - if value.is_shared() { " (shared)" } else { "" }, + value_is_shared, *value.read_lock::().unwrap(), ) }); println!(); } +#[cfg(not(feature = "no_function"))] pub fn main() { println!("Events Handler Example - Main Style"); println!("==================================="); @@ -127,3 +133,8 @@ pub fn main() { println!("Bye!"); } + +#[cfg(feature = "no_function")] +pub fn main() { + panic!("This example does not run under 'no_function'.") +} diff --git a/examples/event_handler_map/main.rs b/examples/event_handler_map/main.rs index 5a6c8aa1..62e0a15f 100644 --- a/examples/event_handler_map/main.rs +++ b/examples/event_handler_map/main.rs @@ -1,5 +1,8 @@ //! Implementation of the Event Handler With State Pattern - Map Style -use rhai::{Dynamic, Engine, Map, Scope, AST}; +use rhai::{Dynamic, Engine, Scope, AST}; + +#[cfg(not(feature = "no_object"))] +use rhai::Map; use std::io::{stdin, stdout, Write}; @@ -17,18 +20,25 @@ fn print_scope(scope: &Scope) { .iter_raw() .enumerate() .for_each(|(i, (name, constant, value))| { + #[cfg(not(feature = "no_closure"))] + let value_is_shared = if value.is_shared() { " (shared)" } else { "" }; + #[cfg(feature = "no_closure")] + let value_is_shared = ""; + println!( "[{}] {}{}{} = {:?}", i + 1, if constant { "const " } else { "" }, name, - if value.is_shared() { " (shared)" } else { "" }, + value_is_shared, *value.read_lock::().unwrap(), ) }); println!(); } +#[cfg(not(feature = "no_function"))] +#[cfg(not(feature = "no_object"))] pub fn main() { println!("Events Handler Example - Map Style"); println!("=================================="); @@ -136,3 +146,8 @@ pub fn main() { println!("Bye!"); } + +#[cfg(any(feature = "no_function", feature = "no_object"))] +pub fn main() { + panic!("This example does not run under 'no_function' or 'no_object'.") +} diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index 528a0a32..83af8683 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -5,7 +5,7 @@ use crate::engine::OP_EQUALS; use crate::eval::{calc_index, calc_offset_len}; use crate::plugin::*; use crate::{ - def_package, Array, Dynamic, Engine, ExclusiveRange, FnPtr, InclusiveRange, NativeCallContext, + def_package, Array, Dynamic, ExclusiveRange, FnPtr, InclusiveRange, NativeCallContext, Position, RhaiResultOf, StaticVec, ERR, INT, }; #[cfg(feature = "no_std")] @@ -179,8 +179,8 @@ pub mod array_functions { let mut arr_len = array.len(); let mut arr = Dynamic::from_array(mem::take(array)); - let (mut a1, mut m1, mut s1) = Engine::calc_data_sizes(&arr, true); - let (a2, m2, s2) = Engine::calc_data_sizes(&item, true); + let (mut a1, mut m1, mut s1) = crate::Engine::calc_data_sizes(&arr, true); + let (a2, m2, s2) = crate::Engine::calc_data_sizes(&item, true); { let mut guard = arr.write_lock::().unwrap();