From 8c20801574b444883047096a67eb4739b7f287ef Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 20 Aug 2022 15:04:17 +0800 Subject: [PATCH] Add parameter to debugger init. --- CHANGELOG.md | 5 +++++ src/api/events.rs | 2 +- src/bin/rhai-dbg.rs | 2 +- src/eval/debugger.rs | 4 ++-- src/eval/global_state.rs | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbe3f96b..1f9266d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ Bug fixes * Fixes panic in interpolated strings with constant expressions. * Using `call_fn_raw` on a function without evaluating the AST no longer panics on namespace-qualified function calls due to `import` statements not run. +Breaking changes +---------------- + +* The first closure passed to `Engine::register_debugger` now takes a single parameter which is a reference to the current `Engine`. + New features ------------ diff --git a/src/api/events.rs b/src/api/events.rs index f77633c4..266c70c8 100644 --- a/src/api/events.rs +++ b/src/api/events.rs @@ -348,7 +348,7 @@ impl Engine { #[inline(always)] pub fn register_debugger( &mut self, - init: impl Fn() -> Dynamic + SendSync + 'static, + init: impl Fn(&Engine) -> Dynamic + SendSync + 'static, callback: impl Fn( EvalContext, crate::eval::DebuggerEvent, diff --git a/src/bin/rhai-dbg.rs b/src/bin/rhai-dbg.rs index d51d877d..30d521fa 100644 --- a/src/bin/rhai-dbg.rs +++ b/src/bin/rhai-dbg.rs @@ -611,7 +611,7 @@ fn main() { #[allow(deprecated)] engine.register_debugger( // Store the current source in the debugger state - || "".into(), + |_| "".into(), // Main debugging interface move |context, event, node, source, pos| { debug_callback(context, event, node, source, pos, &lines) diff --git a/src/eval/debugger.rs b/src/eval/debugger.rs index 2198dda2..bfdb2af5 100644 --- a/src/eval/debugger.rs +++ b/src/eval/debugger.rs @@ -10,10 +10,10 @@ use std::{fmt, iter::repeat, mem}; /// Callback function to initialize the debugger. #[cfg(not(feature = "sync"))] -pub type OnDebuggingInit = dyn Fn() -> Dynamic; +pub type OnDebuggingInit = dyn Fn(&Engine) -> Dynamic; /// Callback function to initialize the debugger. #[cfg(feature = "sync")] -pub type OnDebuggingInit = dyn Fn() -> Dynamic + Send + Sync; +pub type OnDebuggingInit = dyn Fn(&Engine) -> Dynamic + Send + Sync; /// Callback function for debugging. #[cfg(not(feature = "sync"))] diff --git a/src/eval/global_state.rs b/src/eval/global_state.rs index 7421a95a..83b2b076 100644 --- a/src/eval/global_state.rs +++ b/src/eval/global_state.rs @@ -106,7 +106,7 @@ impl GlobalRuntimeState<'_> { crate::eval::DebuggerStatus::CONTINUE }, if let Some((ref init, ..)) = engine.debugger { - init() + init(engine) } else { Dynamic::UNIT },