From c2a796f9c234e92b1f563bf23ac7b8be2ee6c5f6 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 23 Apr 2022 11:53:34 +0800 Subject: [PATCH] Replace Scope display code. --- src/bin/rhai-dbg.rs | 41 ++--------------------------------------- src/bin/rhai-repl.rs | 23 +---------------------- 2 files changed, 3 insertions(+), 61 deletions(-) diff --git a/src/bin/rhai-dbg.rs b/src/bin/rhai-dbg.rs index 7656c31a..ffe0aae1 100644 --- a/src/bin/rhai-dbg.rs +++ b/src/bin/rhai-dbg.rs @@ -154,43 +154,6 @@ fn print_debug_help() { println!(); } -/// Display the current scope. -fn print_scope(scope: &Scope, dedup: bool) { - let flattened_clone; - let scope = if dedup { - flattened_clone = scope.clone_visible(); - &flattened_clone - } else { - scope - }; - - for (i, (name, constant, value)) in scope.iter_raw().enumerate() { - #[cfg(not(feature = "no_closure"))] - let value_is_shared = if value.is_shared() { " (shared)" } else { "" }; - #[cfg(feature = "no_closure")] - let value_is_shared = ""; - - if dedup { - println!( - "{}{}{} = {:?}", - if constant { "const " } else { "" }, - name, - value_is_shared, - *value.read_lock::().unwrap(), - ); - } else { - println!( - "[{}] {}{}{} = {:?}", - i + 1, - if constant { "const " } else { "" }, - name, - value_is_shared, - *value.read_lock::().unwrap(), - ); - } - } -} - // Load script to debug. fn load_script(engine: &Engine) -> (rhai::AST, String) { if let Some(filename) = env::args().skip(1).next() { @@ -365,7 +328,7 @@ fn debug_callback( [] | ["step" | "s"] => break Ok(DebuggerCommand::StepInto), ["over" | "o"] => break Ok(DebuggerCommand::StepOver), ["next" | "n"] => break Ok(DebuggerCommand::Next), - ["scope"] => print_scope(context.scope(), false), + ["scope"] => println!("{}", context.scope()), ["print" | "p", "this"] => { if let Some(value) = context.this_ptr() { println!("=> {:?}", value); @@ -381,7 +344,7 @@ fn debug_callback( } } ["print" | "p"] => { - print_scope(context.scope(), true); + println!("{}", context.scope().clone_visible()); if let Some(value) = context.this_ptr() { println!("this = {:?}", value); } diff --git a/src/bin/rhai-repl.rs b/src/bin/rhai-repl.rs index c0dfa093..0cf59289 100644 --- a/src/bin/rhai-repl.rs +++ b/src/bin/rhai-repl.rs @@ -108,27 +108,6 @@ fn print_keys() { println!(); } -/// Display the scope. -fn print_scope(scope: &Scope) { - for (i, (name, constant, value)) in scope.iter_raw().enumerate() { - #[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, - value_is_shared, - *value.read_lock::().unwrap(), - ) - } - - println!(); -} - // Load script files specified in the command line. #[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_std"))] @@ -458,7 +437,7 @@ fn main() { continue; } "scope" => { - print_scope(&scope); + println!("{}", scope); continue; } #[cfg(not(feature = "no_optimize"))]