Add parameter to debugger init.

This commit is contained in:
Stephen Chung 2022-08-20 15:04:17 +08:00
parent a51f6138f6
commit 8c20801574
5 changed files with 10 additions and 5 deletions

View File

@ -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
------------

View File

@ -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,

View File

@ -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)

View File

@ -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"))]

View File

@ -106,7 +106,7 @@ impl GlobalRuntimeState<'_> {
crate::eval::DebuggerStatus::CONTINUE
},
if let Some((ref init, ..)) = engine.debugger {
init()
init(engine)
} else {
Dynamic::UNIT
},