Skip to content

Commit d87d962

Browse files
committed
chore: no need to register pydebug
1 parent 4d96beb commit d87d962

File tree

4 files changed

+50
-42
lines changed

4 files changed

+50
-42
lines changed

src/legacy/api/EventAPI.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,12 @@ void InitBasicEventListeners() {
777777
if (cmd.starts_with("/")) {
778778
cmd.erase(0, 1);
779779
}
780+
#ifndef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
780781
if (!ProcessDebugEngine(cmd)) {
781782
ev.cancel();
782783
return;
783784
}
785+
#endif
784786
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
785787
if (!NodeJsHelper::processConsoleNpmCmd(cmd)) {
786788
ev.cancel();

src/legacy/main/BuiltinCommands.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,33 @@
1616
#include "PythonHelper.h"
1717
#endif
1818

19-
extern bool isInConsoleDebugMode;
20-
extern ScriptEngine* debugEngine;
21-
std::shared_ptr<ll::io::Logger> debugLogger = ll::io::LoggerRegistry::getInstance().getOrCreate("LSEDEBUG");
22-
inline void printConsoleSymbol() { debugLogger->info("> "); }
19+
extern bool InConsoleDebugMode;
20+
extern ScriptEngine* DebugEngine;
21+
std::shared_ptr<ll::io::Logger> DebugCmdLogger = ll::io::LoggerRegistry::getInstance().getOrCreate("LSEDEBUG");
22+
23+
inline void PrintDebugSign() { DebugCmdLogger->info("> "); }
2324

2425
bool ProcessDebugEngine(const std::string& cmd) {
2526
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
2627
// process python debug seperately
2728
return PythonHelper::processPythonDebugEngine(cmd);
2829
#endif
29-
if (isInConsoleDebugMode) {
30-
EngineScope enter(debugEngine);
30+
if (InConsoleDebugMode) {
31+
EngineScope enter(DebugEngine);
3132
auto& logger = lse::LegacyScriptEngine::getInstance().getSelf().getLogger();
3233
try {
3334
if (cmd == "stop" || cmd == LLSE_DEBUG_CMD) {
3435
return true;
3536
} else {
36-
auto result = debugEngine->eval(cmd);
37+
auto result = DebugEngine->eval(cmd);
3738
std::ostringstream sout;
3839
PrintValue(sout, result);
3940
logger.info(sout.str());
40-
printConsoleSymbol();
41+
PrintDebugSign();
4142
}
4243
} catch (...) {
4344
ll::error_utils::printCurrentException(logger);
44-
printConsoleSymbol();
45+
PrintDebugSign();
4546
}
4647
return false;
4748
}
@@ -53,34 +54,37 @@ struct EngineDebugCommand {
5354
};
5455

5556
void RegisterDebugCommand() {
56-
debugLogger->setFormatter(ll::makePolymorphic<lse::io::DirectFormatter>());
57+
DebugCmdLogger->setFormatter(ll::makePolymorphic<lse::io::DirectFormatter>());
58+
// Node.js engine doesn't support debug engine, Python engine don't need to register command.
59+
#if (!defined LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS) && (!defined LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON)
5760
auto& command = ll::command::CommandRegistrar::getInstance()
5861
.getOrCreateCommand(LLSE_DEBUG_CMD, "Debug LegacyScriptEngine", CommandPermissionLevel::Owner);
5962
command.overload<EngineDebugCommand>().optional("eval").execute(
6063
[](CommandOrigin const&, CommandOutput& output, EngineDebugCommand const& param) {
6164
auto& logger = lse::LegacyScriptEngine::getInstance().getSelf().getLogger();
6265
if (!param.eval.getText().empty()) {
63-
EngineScope enter(debugEngine);
66+
EngineScope enter(DebugEngine);
6467
try {
65-
auto result = debugEngine->eval(param.eval.getText());
68+
auto result = DebugEngine->eval(param.eval.getText());
6669
std::ostringstream sout;
6770
PrintValue(sout, result);
6871
output.success(sout.str());
6972
} catch (...) {
7073
ll::error_utils::printCurrentException(logger);
7174
}
7275
} else {
73-
if (isInConsoleDebugMode) {
76+
if (InConsoleDebugMode) {
7477
// EndDebug
7578
logger.info("Debug mode ended");
76-
isInConsoleDebugMode = false;
79+
InConsoleDebugMode = false;
7780
} else {
7881
// StartDebug
7982
logger.info("Debug mode begins");
80-
isInConsoleDebugMode = true;
81-
printConsoleSymbol();
83+
InConsoleDebugMode = true;
84+
PrintDebugSign();
8285
}
8386
}
8487
}
8588
);
89+
#endif
8690
}

src/legacy/main/PythonHelper.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
const unsigned long PIP_EXECUTE_TIMEOUT = 1800 * 1000;
1818

1919
// pre-declare
20-
extern void BindAPIs(ScriptEngine* engine);
21-
extern bool isInConsoleDebugMode;
22-
extern ScriptEngine* debugEngine;
20+
extern void BindAPIs(ScriptEngine* engine);
21+
extern bool InConsoleDebugMode;
22+
extern ScriptEngine* DebugEngine;
23+
extern std::shared_ptr<ll::io::Logger> DebugCmdLogger;
2324

2425
struct PyConfig;
2526
typedef PyObject* (*create_stdio_func_type)(
@@ -142,8 +143,8 @@ std::string getPluginPackDependencyFilePath(const std::string& dirPath) {
142143
else return "";
143144
}
144145

145-
inline void OUTPUT_DEBUG_SIGN() { std::cout << ">>> " << std::flush; }
146-
inline void OUTPUT_DEBUG_NEED_MORE_CODE_SIGN() { std::cout << "... " << std::flush; }
146+
inline void PrintPyDebugSign() { DebugCmdLogger->info(">>> "); }
147+
inline void OutputDebugNeedMoreCodeSign() { DebugCmdLogger->info("... "); }
147148
std::string codeBuffer = "";
148149
bool isInsideCodeBlock = false;
149150

@@ -157,22 +158,23 @@ static PyObject* getPyGlobalDict() {
157158

158159
bool processPythonDebugEngine(const std::string& cmd) {
159160
if (cmd == LLSE_DEBUG_CMD) {
160-
if (isInConsoleDebugMode) {
161+
auto& logger = lse::LegacyScriptEngine::getInstance().getSelf().getLogger();
162+
if (InConsoleDebugMode) {
161163
// EndDebug
162-
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().info("Debug mode ended");
163-
isInConsoleDebugMode = false;
164+
logger.info("Debug mode ended");
165+
InConsoleDebugMode = false;
164166
} else {
165167
// StartDebug
166-
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().info("Debug mode begins");
168+
logger.info("Debug mode begins");
167169
codeBuffer.clear();
168-
isInsideCodeBlock = false;
169-
isInConsoleDebugMode = true;
170-
OUTPUT_DEBUG_SIGN();
170+
isInsideCodeBlock = false;
171+
InConsoleDebugMode = true;
172+
PrintPyDebugSign();
171173
}
172174
return false;
173175
}
174-
if (isInConsoleDebugMode) {
175-
EngineScope enter(debugEngine);
176+
if (InConsoleDebugMode) {
177+
EngineScope enter(DebugEngine);
176178
if (cmd == "stop") {
177179
return true;
178180
} else {
@@ -185,7 +187,7 @@ bool processPythonDebugEngine(const std::string& cmd) {
185187
} else {
186188
// add a new line to buffer
187189
codeBuffer += cmd + "\n";
188-
OUTPUT_DEBUG_NEED_MORE_CODE_SIGN();
190+
OutputDebugNeedMoreCodeSign();
189191
return false;
190192
}
191193
} else {
@@ -194,7 +196,7 @@ bool processPythonDebugEngine(const std::string& cmd) {
194196
// begin code block mode
195197
isInsideCodeBlock = true;
196198
codeBuffer = cmd + "\n";
197-
OUTPUT_DEBUG_NEED_MORE_CODE_SIGN();
199+
OutputDebugNeedMoreCodeSign();
198200
return false;
199201
} else {
200202
codeBuffer = cmd;
@@ -207,13 +209,13 @@ bool processPythonDebugEngine(const std::string& cmd) {
207209
auto exp = script::py_interop::getAndClearLastException();
208210
throw exp;
209211
}
210-
} catch (const Exception& e) {
212+
} catch (...) {
211213
isInsideCodeBlock = false;
212214
codeBuffer.clear();
213-
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger());
215+
ll::error_utils::printCurrentException(logger);
214216
}
215217
}
216-
OUTPUT_DEBUG_SIGN();
218+
PrintPyDebugSign();
217219
return false;
218220
}
219221
return true;

src/lse/Entry.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ void InitLocalShareData();
5555
void InitMessageSystem();
5656
void InitSafeGuardRecord();
5757
void RegisterDebugCommand();
58-
bool isInConsoleDebugMode; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
59-
script::ScriptEngine* debugEngine; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
58+
bool InConsoleDebugMode; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
59+
script::ScriptEngine* DebugEngine; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
6060

6161
namespace lse {
6262

@@ -75,14 +75,14 @@ bool LegacyScriptEngine::enable() {
7575
logger.error("Failed to enable MoreGlobal"_tr());
7676
}
7777
ll::service::PlayerInfo::getInstance();
78-
#ifndef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
78+
7979
try {
8080
RegisterDebugCommand();
81-
} catch (const std::exception& error) {
82-
logger.error("Failed to enable: {0}"_tr(error.what()));
81+
} catch (...) {
82+
logger.error("Failed to enable: {0}"_tr("RegisterDebugCommand"));
83+
ll::error_utils::printCurrentException(logger);
8384
return false;
8485
}
85-
#endif
8686
return true;
8787
}
8888

@@ -172,7 +172,7 @@ void loadDebugEngine(const ll::mod::NativeMod& self) {
172172
}
173173
scriptEngine->eval(baseLibContent.value());
174174

175-
debugEngine = scriptEngine;
175+
DebugEngine = scriptEngine;
176176
#endif
177177
}
178178

0 commit comments

Comments
 (0)