From 8d07d8e00a7235223425d529de1ae589ddf28bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hozda?= Date: Fri, 9 Feb 2018 22:27:41 +0100 Subject: [PATCH] lock debug messages behind 'debug_msgs' feature --- Cargo.toml | 3 +++ src/engine.rs | 4 ++-- src/lib.rs | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1a7eef77..16bdba55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,6 @@ include = [ "scripts/*.rhai", "Cargo.toml" ] + +[features] +debug_msgs = [] diff --git a/src/engine.rs b/src/engine.rs index a00fbc2c..4b6438d3 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -160,7 +160,7 @@ impl Engine { ident: String, args: Vec<&mut Any>, ) -> Result, EvalAltResult> { - println!( + debug_println!( "Trying to call function {:?} with args {:?}", ident, args.iter().map(|x| (&**x).type_id()).collect::>() @@ -196,7 +196,7 @@ impl Engine { } pub fn register_fn_raw(&mut self, ident: String, args: Option>, f: Box) { - println!("Register; {:?} with args {:?}", ident, args,); + debug_println!("Register; {:?} with args {:?}", ident, args); let spec = FnSpec { ident, args }; diff --git a/src/lib.rs b/src/lib.rs index f03ff9d5..14bc19a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,13 @@ #![allow(warnings, unknown_lints, type_complexity, new_without_default_derive, needless_pass_by_value, too_many_arguments)] +// needs to be here, because order matters for macros +macro_rules! debug_println { + () => (#[cfg(feature = "debug_msgs")] {print!("\n")}); + ($fmt:expr) => (#[cfg(feature = "debug_msgs")] {print!(concat!($fmt, "\n"))}); + ($fmt:expr, $($arg:tt)*) => (#[cfg(feature = "debug_msgs")] {print!(concat!($fmt, "\n"), $($arg)*)}); +} + mod any; mod call; mod engine; @@ -46,3 +53,4 @@ mod tests; pub use any::Any; pub use engine::{Engine, EvalAltResult, Scope}; pub use fn_register::RegisterFn; +