From da5a750965dbec5a2c003faa8fb9f1dd110ccce8 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 18 May 2026 17:25:29 +0800 Subject: Implement REPL execution with hooks and argument splitting --- mingling_core/src/program/exec.rs | 40 +++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'mingling_core/src/program/exec.rs') diff --git a/mingling_core/src/program/exec.rs b/mingling_core/src/program/exec.rs index 1b756a1..72a20b9 100644 --- a/mingling_core/src/program/exec.rs +++ b/mingling_core/src/program/exec.rs @@ -12,17 +12,38 @@ pub mod error; pub async fn exec( program: &'static Program, ) -> Result +where + C: ProgramCollect, +{ + let args = program.args.clone(); + exec_with_args(program, args).await +} + +#[cfg(not(feature = "async"))] +pub fn exec(program: &'static Program) -> Result +where + C: ProgramCollect, +{ + let args = program.args.clone(); + exec_with_args(program, args) +} + +#[cfg(feature = "async")] +pub async fn exec_with_args( + program: &'static Program, + args: Vec, +) -> Result where C: ProgramCollect, { // Run hooks - program.run_hook_pre_dispatch(&program.args); + program.run_hook_pre_dispatch(&args); #[cfg(not(feature = "dispatch_tree"))] - let mut current = dispatch_args_dynamic(program, &program.args)?; + let mut current = dispatch_args_dynamic(program, &args)?; #[cfg(feature = "dispatch_tree")] - let mut current = C::dispatch_args_trie(&program.args)?; + let mut current = C::dispatch_args_trie(&args)?; // Run hook program.run_hook_post_dispatch(¤t.member_id); @@ -102,18 +123,21 @@ where } #[cfg(not(feature = "async"))] -pub fn exec(program: &'static Program) -> Result +pub fn exec_with_args( + program: &'static Program, + args: Vec, +) -> Result where C: ProgramCollect, { // Run hooks - program.run_hook_pre_dispatch(&program.args); + program.run_hook_pre_dispatch(&args); #[cfg(not(feature = "dispatch_tree"))] - let mut current = dispatch_args_dynamic(program, &program.args)?; + let mut current = dispatch_args_dynamic(program, &args)?; #[cfg(feature = "dispatch_tree")] - let mut current = C::dispatch_args_trie(&program.args)?; + let mut current = C::dispatch_args_trie(&args)?; // Run hook program.run_hook_post_dispatch(¤t.member_id); @@ -212,7 +236,7 @@ where } Err(ProgramInternalExecuteError::DispatcherNotFound) => { // No matching Dispatcher is found - C::build_dispatcher_not_found(program.args.clone()) + C::build_dispatcher_not_found(args.clone()) } Err(e) => return Err(e), }; -- cgit