From 193f0fb6c7a215b2e2b0105959eb41ba8779a39c Mon Sep 17 00:00:00 2001 From: ShrBox Date: Tue, 23 Jan 2024 13:58:24 +0800 Subject: [PATCH] refactor: better debug command --- src/main/BuiltinCommands.cpp | 49 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/main/BuiltinCommands.cpp b/src/main/BuiltinCommands.cpp index 55989917..76f32b61 100644 --- a/src/main/BuiltinCommands.cpp +++ b/src/main/BuiltinCommands.cpp @@ -27,20 +27,6 @@ bool ProcessDebugEngine(const std::string& cmd) { // process python debug seperately return PythonHelper::processPythonDebugEngine(cmd); #endif - - if (cmd == LLSE_DEBUG_CMD) { - if (isInConsoleDebugMode) { - // EndDebug - logger.info("Debug mode ended"); - isInConsoleDebugMode = false; - } else { - // StartDebug - logger.info("Debug mode begins"); - isInConsoleDebugMode = true; - OUTPUT_DEBUG_SIGN(); - } - return false; - } if (isInConsoleDebugMode) { EngineScope enter(debugEngine); try { @@ -64,23 +50,36 @@ bool ProcessDebugEngine(const std::string& cmd) { void RegisterDebugCommand() { auto command = DynamicCommand::createCommand( ll::service::getCommandRegistry(), - "lsedebug", + LLSE_DEBUG_CMD, "Debug LegacyScriptEngine", CommandPermissionLevel::Owner ); command->mandatory("eval", DynamicCommand::ParameterType::RawText); command->addOverload("eval"); - command->setCallback([](DynamicCommand const& cmd, - CommandOrigin const& origin, - CommandOutput& output, + command->setCallback([](DynamicCommand const&, + CommandOrigin const&, + CommandOutput&, std::unordered_map& results) { - EngineScope enter(debugEngine); - try { - auto result = debugEngine->eval(results["eval"].getRaw()); - PrintValue(std::cout, result); - std::cout << std::endl; - } catch (Exception& e) { - PrintException(e); + if (results["eval"].isSet) { + EngineScope enter(debugEngine); + try { + auto result = debugEngine->eval(results["eval"].getRaw()); + PrintValue(std::cout, result); + std::cout << std::endl; + } catch (Exception& e) { + PrintException(e); + } + } else { + if (isInConsoleDebugMode) { + // EndDebug + logger.info("Debug mode ended"); + isInConsoleDebugMode = false; + } else { + // StartDebug + logger.info("Debug mode begins"); + isInConsoleDebugMode = true; + OUTPUT_DEBUG_SIGN(); + } } }); DynamicCommand::setup(ll::service::getCommandRegistry(), std::move(command));