Refactor and add state to debugger.

This commit is contained in:
Stephen Chung
2022-01-28 18:59:18 +08:00
parent 20baae71d4
commit 66af69aaff
30 changed files with 693 additions and 624 deletions

View File

@@ -154,10 +154,7 @@ impl Engine {
arg_values: impl AsMut<[Dynamic]>,
) -> RhaiResult {
let state = &mut EvalState::new();
let global = &mut GlobalRuntimeState::new();
#[cfg(feature = "debugging")]
global.debugger.activate(self.debugger.is_some());
let global = &mut GlobalRuntimeState::new(self);
let statements = ast.statements();

View File

@@ -184,10 +184,7 @@ impl Engine {
scope: &mut Scope,
ast: &AST,
) -> RhaiResultOf<T> {
let global = &mut GlobalRuntimeState::new();
#[cfg(feature = "debugging")]
global.debugger.activate(self.debugger.is_some());
let global = &mut GlobalRuntimeState::new(self);
let result = self.eval_ast_with_scope_raw(scope, global, ast, 0)?;

View File

@@ -260,12 +260,13 @@ impl Engine {
self.debug = Some(Box::new(callback));
self
}
/// _(debugging)_ Register a callback for debugging.
/// _(debugging)_ Register callbacks for debugging.
/// Exported under the `debugging` feature only.
#[cfg(feature = "debugging")]
#[inline(always)]
pub fn on_debugger(
&mut self,
init: impl Fn() -> Dynamic + SendSync + 'static,
callback: impl Fn(
&mut EvalContext,
crate::ast::ASTNode,
@@ -275,7 +276,7 @@ impl Engine {
+ SendSync
+ 'static,
) -> &mut Self {
self.debugger = Some(Box::new(callback));
self.debugger = Some((Box::new(init), Box::new(callback)));
self
}
}

View File

@@ -1037,9 +1037,9 @@ impl Engine {
signatures.extend(self.global_namespace().gen_fn_signatures());
self.global_sub_modules.iter().for_each(|(name, m)| {
for (name, m) in &self.global_sub_modules {
signatures.extend(m.gen_fn_signatures().map(|f| format!("{}::{}", name, f)))
});
}
signatures.extend(
self.global_modules

View File

@@ -45,9 +45,7 @@ impl Engine {
#[inline]
pub fn run_ast_with_scope(&self, scope: &mut Scope, ast: &AST) -> RhaiResultOf<()> {
let state = &mut EvalState::new();
let global = &mut GlobalRuntimeState::new();
#[cfg(feature = "debugging")]
global.debugger.activate(self.debugger.is_some());
let global = &mut GlobalRuntimeState::new(self);
global.source = ast.source_raw().clone();
#[cfg(not(feature = "no_module"))]