Add debugging interface.

This commit is contained in:
Stephen Chung
2022-01-24 17:04:40 +08:00
parent 182870c9ed
commit fc87dec128
24 changed files with 1255 additions and 414 deletions

View File

@@ -155,6 +155,10 @@ impl Engine {
) -> RhaiResult {
let state = &mut EvalState::new();
let global = &mut GlobalRuntimeState::new();
#[cfg(feature = "debugging")]
global.debugger.activate(self.debugger.is_some());
let statements = ast.statements();
let orig_scope_len = scope.len();

View File

@@ -186,6 +186,9 @@ impl Engine {
) -> RhaiResultOf<T> {
let global = &mut GlobalRuntimeState::new();
#[cfg(feature = "debugging")]
global.debugger.activate(self.debugger.is_some());
let result = self.eval_ast_with_scope_raw(scope, global, ast, 0)?;
let typ = self.map_type_name(result.type_name());

View File

@@ -64,7 +64,7 @@ impl Engine {
self.resolve_var = Some(Box::new(callback));
self
}
/// _(internals)_ Provide a callback that will be invoked during parsing to remap certain tokens.
/// _(internals)_ Register a callback that will be invoked during parsing to remap certain tokens.
/// Exported under the `internals` feature only.
///
/// # Callback Function Signature
@@ -261,4 +261,22 @@ impl Engine {
self.debug = Some(Box::new(callback));
self
}
/// _(debugging)_ Register a callback for debugging.
/// Exported under the `debugging` feature only.
#[cfg(feature = "debugging")]
#[inline(always)]
pub fn on_debugger(
&mut self,
callback: impl Fn(
&mut EvalContext,
crate::ast::ASTNode,
Option<&str>,
Position,
) -> crate::eval::DebuggerCommand
+ SendSync
+ 'static,
) -> &mut Self {
self.debugger = Some(Box::new(callback));
self
}
}

View File

@@ -44,8 +44,10 @@ impl Engine {
/// Evaluate an [`AST`] with own scope, returning any error (if any).
#[inline]
pub fn run_ast_with_scope(&self, scope: &mut Scope, ast: &AST) -> RhaiResultOf<()> {
let state = &mut EvalState::new();
let global = &mut GlobalRuntimeState::new();
let mut state = EvalState::new();
#[cfg(feature = "debugging")]
global.debugger.activate(self.debugger.is_some());
global.source = ast.source_raw().clone();
#[cfg(not(feature = "no_module"))]
@@ -64,7 +66,7 @@ impl Engine {
} else {
&lib
};
self.eval_global_statements(scope, global, &mut state, statements, lib, 0)?;
self.eval_global_statements(scope, global, state, statements, lib, 0)?;
}
Ok(())
}