Print this.

This commit is contained in:
Stephen Chung 2022-02-09 08:11:26 +08:00
parent 1b4184ef16
commit ddc66e7fb8

View File

@ -101,6 +101,7 @@ fn print_debug_help() {
println!("quit, q, exit, kill => quit"); println!("quit, q, exit, kill => quit");
println!("scope => print the scope"); println!("scope => print the scope");
println!("print, p => print all variables de-duplicated"); println!("print, p => print all variables de-duplicated");
println!("print/p this => print the `this` pointer");
println!("print/p <variable> => print the current value of a variable"); println!("print/p <variable> => print the current value of a variable");
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
println!("imports => print all imported modules"); println!("imports => print all imported modules");
@ -167,8 +168,6 @@ fn print_scope(scope: &Scope, dedup: bool) {
); );
} }
} }
println!();
} }
fn main() { fn main() {
@ -336,18 +335,26 @@ fn main() {
["over", ..] => break Ok(DebuggerCommand::StepOver), ["over", ..] => break Ok(DebuggerCommand::StepOver),
["next" | "n", ..] => break Ok(DebuggerCommand::Next), ["next" | "n", ..] => break Ok(DebuggerCommand::Next),
["scope", ..] => print_scope(context.scope(), false), ["scope", ..] => print_scope(context.scope(), false),
["print" | "p", "this"] => {
if let Some(value) = context.this_ptr() {
println!("=> {:?}", value);
} else {
println!("`this` pointer is unbound.");
}
}
["print" | "p", var_name, ..] => { ["print" | "p", var_name, ..] => {
if let Some(value) = context.scope().get_value::<Dynamic>(var_name) { if let Some(value) = context.scope().get_value::<Dynamic>(var_name) {
if value.is::<()>() { println!("=> {:?}", value);
println!("=> ()");
} else {
println!("=> {}", value);
}
} else { } else {
eprintln!("Variable not found: {}", var_name); eprintln!("Variable not found: {}", var_name);
} }
} }
["print" | "p"] => print_scope(context.scope(), true), ["print" | "p"] => {
print_scope(context.scope(), true);
if let Some(value) = context.this_ptr() {
println!("this = {:?}", value);
}
}
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
["imports", ..] => { ["imports", ..] => {
for (i, (name, module)) in context for (i, (name, module)) in context