From be315aebaf58355c86a9f226937a23cbbca74e46 Mon Sep 17 00:00:00 2001 From: J Henry Waugh Date: Thu, 6 Aug 2020 18:36:15 -0500 Subject: [PATCH 1/3] Fix breakage due to write_lock() --- codegen/src/function.rs | 4 ++-- codegen/src/module.rs | 2 +- codegen/src/rhai_module.rs | 2 +- src/fn_register.rs | 8 ++++---- src/lib.rs | 2 ++ 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/codegen/src/function.rs b/codegen/src/function.rs index 5d869a2b..6ee13ed8 100644 --- a/codegen/src/function.rs +++ b/codegen/src/function.rs @@ -220,7 +220,7 @@ impl ExportedFn { } }; let downcast_span = quote_spanned!( - arg_type.span()=> &mut *args[0usize].write_lock::<#arg_type>().unwrap()); + arg_type.span()=> &mut args[0usize].write_lock::<#arg_type>().unwrap()); unpack_stmts.push( syn::parse2::(quote! { let #var: &mut _ = #downcast_span; @@ -784,7 +784,7 @@ mod generate_tests { args.len(), 2usize), Position::none()))); } let arg1 = args[1usize].downcast_clone::().unwrap(); - let arg0: &mut _ = args[0usize].write_lock::().unwrap(); + let arg0: &mut _ = &mut args[0usize].write_lock::().unwrap(); Ok(Dynamic::from(increment(arg0, arg1))) } diff --git a/codegen/src/module.rs b/codegen/src/module.rs index 48d9758c..9db6a3cd 100644 --- a/codegen/src/module.rs +++ b/codegen/src/module.rs @@ -667,7 +667,7 @@ mod generate_tests { format!("wrong arg count: {} != {}", args.len(), 1usize), Position::none()))); } - let arg0: &mut _ = args[0usize].write_lock::().unwrap(); + let arg0: &mut _ = &mut args[0usize].write_lock::().unwrap(); Ok(Dynamic::from(increment(arg0))) } diff --git a/codegen/src/rhai_module.rs b/codegen/src/rhai_module.rs index 1a2b1021..08c7f11f 100644 --- a/codegen/src/rhai_module.rs +++ b/codegen/src/rhai_module.rs @@ -26,7 +26,7 @@ pub(crate) fn generate_body( let mut gen_fn_tokens: Vec = Vec::new(); for function in fns { let fn_token_name = syn::Ident::new( - &format!("{}_Token", function.name().to_string()), + &format!("{}_token", function.name().to_string()), function.name().span(), ); let fn_literal = diff --git a/src/fn_register.rs b/src/fn_register.rs index 91974c2e..104b305f 100644 --- a/src/fn_register.rs +++ b/src/fn_register.rs @@ -39,10 +39,10 @@ pub trait RegisterPlugin { /// fn is_varadic(&self) -> bool { false } /// /// fn call(&self, args: &mut[&mut Dynamic], pos: Position) -> Result> { - /// let x1: &FLOAT = args[0].downcast_ref::().unwrap(); - /// let y1: &FLOAT = args[1].downcast_ref::().unwrap(); - /// let x2: &FLOAT = args[2].downcast_ref::().unwrap(); - /// let y2: &FLOAT = args[3].downcast_ref::().unwrap(); + /// let x1: FLOAT = args[0].downcast_clone::().unwrap(); + /// let y1: FLOAT = args[1].downcast_clone::().unwrap(); + /// let x2: FLOAT = args[2].downcast_clone::().unwrap(); + /// let y2: FLOAT = args[3].downcast_clone::().unwrap(); /// let square_sum = (y2 - y1).abs().powf(2.0) + (x2 -x1).abs().powf(2.0); /// Ok(Dynamic::from(square_sum.sqrt())) /// } diff --git a/src/lib.rs b/src/lib.rs index b6177699..a8a783d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,6 +102,8 @@ pub use rhai_codegen::*; #[cfg(not(feature = "no_function"))] pub use parser::FnAccess; +#[cfg(feature = "no_function")] +pub use parser::FnAccess; #[cfg(not(feature = "no_function"))] pub use fn_func::Func; From 893a084b7ac9dce9bf033b9af39579caf69dd342 Mon Sep 17 00:00:00 2001 From: J Henry Waugh Date: Thu, 6 Aug 2020 19:09:13 -0500 Subject: [PATCH 2/3] Avoid failing fast on features GHA workflow --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 39610a97..0384c01c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,6 +38,7 @@ jobs: - {toolchain: stable, os: macos-latest, experimental: false, flags: ""} - {toolchain: beta, os: ubuntu-latest, experimental: false, flags: ""} - {toolchain: nightly, os: ubuntu-latest, experimental: true, flags: ""} + fail-fast: false steps: - name: Checkout uses: actions/checkout@v2 From 75bcbb74eb540109584865a774884716ae87d174 Mon Sep 17 00:00:00 2001 From: J Henry Waugh Date: Thu, 6 Aug 2020 19:41:06 -0500 Subject: [PATCH 3/3] Fix unrelated CI failure for features --- src/fn_register.rs | 53 +++++++++++++++++++++++++++++++--------------- tests/plugins.rs | 2 ++ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/fn_register.rs b/src/fn_register.rs index 104b305f..9645fba9 100644 --- a/src/fn_register.rs +++ b/src/fn_register.rs @@ -26,25 +26,36 @@ pub trait RegisterPlugin { /// # Example /// /// ``` - /// use rhai::{FLOAT, INT, Module, ModuleResolver, RegisterFn, RegisterPlugin}; + /// # #[cfg(not(feature = "no_float"))] + /// use rhai::FLOAT as NUMBER; + /// # #[cfg(feature = "no_float")] + /// use rhai::INT as NUMBER; + /// # #[cfg(not(feature = "no_module"))] + /// use rhai::{Module, ModuleResolver, RegisterFn, RegisterPlugin}; + /// # #[cfg(not(feature = "no_module"))] /// use rhai::plugin::*; + /// # #[cfg(not(feature = "no_module"))] /// use rhai::module_resolvers::*; /// /// // A function we want to expose to Rhai. /// #[derive(Copy, Clone)] /// struct DistanceFunction(); /// + /// # #[cfg(not(feature = "no_module"))] /// impl PluginFunction for DistanceFunction { /// fn is_method_call(&self) -> bool { false } /// fn is_varadic(&self) -> bool { false } /// /// fn call(&self, args: &mut[&mut Dynamic], pos: Position) -> Result> { - /// let x1: FLOAT = args[0].downcast_clone::().unwrap(); - /// let y1: FLOAT = args[1].downcast_clone::().unwrap(); - /// let x2: FLOAT = args[2].downcast_clone::().unwrap(); - /// let y2: FLOAT = args[3].downcast_clone::().unwrap(); + /// let x1: NUMBER = args[0].downcast_clone::().unwrap(); + /// let y1: NUMBER = args[1].downcast_clone::().unwrap(); + /// let x2: NUMBER = args[2].downcast_clone::().unwrap(); + /// let y2: NUMBER = args[3].downcast_clone::().unwrap(); + /// # #[cfg(not(feature = "no_float"))] /// let square_sum = (y2 - y1).abs().powf(2.0) + (x2 -x1).abs().powf(2.0); - /// Ok(Dynamic::from(square_sum.sqrt())) + /// # #[cfg(feature = "no_float")] + /// let square_sum = (y2 - y1).abs().pow(2) + (x2 -x1).abs().pow(2); + /// Ok(Dynamic::from(square_sum)) /// } /// /// fn clone_boxed(&self) -> Box { @@ -52,10 +63,10 @@ pub trait RegisterPlugin { /// } /// /// fn input_types(&self) -> Box<[std::any::TypeId]> { - /// vec![std::any::TypeId::of::(), - /// std::any::TypeId::of::(), - /// std::any::TypeId::of::(), - /// std::any::TypeId::of::()].into_boxed_slice() + /// vec![std::any::TypeId::of::(), + /// std::any::TypeId::of::(), + /// std::any::TypeId::of::(), + /// std::any::TypeId::of::()].into_boxed_slice() /// } /// } /// @@ -63,10 +74,11 @@ pub trait RegisterPlugin { /// #[derive(Copy, Clone)] /// pub struct AdvancedMathPlugin(); /// + /// # #[cfg(not(feature = "no_module"))] /// impl Plugin for AdvancedMathPlugin { /// fn register_contents(self, engine: &mut Engine) { /// // Plugins are allowed to have side-effects on the engine. - /// engine.register_fn("get_mystic_number", || { 42 as FLOAT }); + /// engine.register_fn("get_mystic_number", || { 42 as NUMBER }); /// /// // Main purpose: create a module to expose the functions to Rhai. /// // @@ -74,10 +86,10 @@ pub trait RegisterPlugin { /// // modules. /// let mut m = Module::new(); /// m.set_fn("euclidean_distance".to_string(), FnAccess::Public, - /// &[std::any::TypeId::of::(), - /// std::any::TypeId::of::(), - /// std::any::TypeId::of::(), - /// std::any::TypeId::of::()], + /// &[std::any::TypeId::of::(), + /// std::any::TypeId::of::(), + /// std::any::TypeId::of::(), + /// std::any::TypeId::of::()], /// CallableFunction::from_plugin(DistanceFunction())); /// let mut r = StaticModuleResolver::new(); /// r.insert("Math::Advanced".to_string(), m); @@ -88,12 +100,19 @@ pub trait RegisterPlugin { /// /// # fn main() -> Result<(), Box> { /// + /// # #[cfg(not(feature = "no_module"))] { /// let mut engine = Engine::new(); /// engine.register_plugin(AdvancedMathPlugin()); /// - /// assert_eq!(engine.eval::( + /// # #[cfg(feature = "no_float")] + /// assert_eq!(engine.eval::( /// r#"import "Math::Advanced" as math; - /// let x = math::euclidean_distance(0.0, 1.0, 0.0, get_mystic_number()); x"#)?, 41.0); + /// let x = math::euclidean_distance(0, 1, 0, get_mystic_number()); x"#)?, 1681); + /// # #[cfg(not(feature = "no_float"))] + /// assert_eq!(engine.eval::( + /// r#"import "Math::Advanced" as math; + /// let x = math::euclidean_distance(0.0, 1.0, 0.0, get_mystic_number()); x"#)?, 1681.0); + /// # } // end cfg /// # Ok(()) /// # } /// ``` diff --git a/tests/plugins.rs b/tests/plugins.rs index adf1840e..1b701ddd 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -1,3 +1,5 @@ +#![cfg(not(any(feature = "no_index", feature = "no_module")))] + use rhai::plugin::*; use rhai::{Engine, EvalAltResult, INT};