Skip to content

Commit 65c7ed2

Browse files
committed
refactor: refactoring Entry
1 parent d1695d1 commit 65c7ed2

36 files changed

+482
-340
lines changed

src/legacy/api/APIHelp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ Local<Value> JsonToValue(std::string jsonStr) {
332332
auto j = ordered_json::parse(jsonStr, nullptr, true, true);
333333
return JsonToValue(j);
334334
} catch (const ordered_json::exception& e) {
335-
lse::getSelfModInstance().getLogger().warn(
335+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().warn(
336336
"{}{}",
337337
"JSON parse error"_tr(),
338338
ll::string_utils::tou8str(e.what())

src/legacy/api/APIHelp.h

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ std::string ValueKindToString(const ValueKind& kind);
2525
// 输出脚本调用堆栈,API名称,以及插件名
2626
inline void LOG_ERROR_WITH_SCRIPT_INFO(std::string const& func = "", std::string const& msg = "") {
2727
auto e = script::Exception(msg);
28-
lse::getSelfModInstance().getLogger().error("script::Exception: {0}\n{1}", e.message(), e.stacktrace());
29-
lse::getSelfModInstance().getLogger().error("In API: " + func);
30-
lse::getSelfModInstance().getLogger().error("In Plugin: " + getEngineOwnData()->pluginName);
28+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error(
29+
"script::Exception: {0}\n{1}",
30+
e.message(),
31+
e.stacktrace()
32+
);
33+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("In API: " + func);
34+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("In Plugin: " + getEngineOwnData()->pluginName);
3135
}
3236

3337
// 参数类型错误输出
@@ -60,12 +64,12 @@ inline void LOG_WRONG_ARGS_COUNT(std::string const& func = "") {
6064
// 截获引擎异常
6165
#define CATCH(LOG) \
6266
catch (const Exception& e) { \
63-
ll::error_utils::printException(e, lse::getSelfModInstance().getLogger()); \
67+
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
6468
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
6569
return Local<Value>(); \
6670
} \
6771
catch (...) { \
68-
ll::error_utils::printCurrentException(lse::getSelfModInstance().getLogger()); \
72+
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
6973
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
7074
return Local<Value>(); \
7175
}
@@ -94,46 +98,50 @@ inline void LOG_WRONG_ARGS_COUNT(std::string const& func = "") {
9498
// 截获引擎异常_Constructor
9599
#define CATCH_C(LOG) \
96100
catch (const Exception& e) { \
97-
ll::error_utils::printException(e, lse::getSelfModInstance().getLogger()); \
101+
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
98102
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
99103
return nullptr; \
100104
} \
101105
catch (...) { \
102-
ll::error_utils::printCurrentException(lse::getSelfModInstance().getLogger()); \
106+
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
103107
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
104108
return nullptr; \
105109
}
106110

107111
// 截获引擎异常_Setter
108112
#define CATCH_S(LOG) \
109113
catch (const Exception& e) { \
110-
ll::error_utils::printException(e, lse::getSelfModInstance().getLogger()); \
114+
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
111115
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
112116
return; \
113117
} \
114118
catch (...) { \
115-
ll::error_utils::printCurrentException(lse::getSelfModInstance().getLogger()); \
119+
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
116120
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
117121
return; \
118122
}
119123

120124
// 截获引擎异常_Constructor
121125
#define CATCH_WITHOUT_RETURN(LOG) \
122126
catch (const Exception& e) { \
123-
ll::error_utils::printException(e, lse::getSelfModInstance().getLogger()); \
127+
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
124128
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
125129
} \
126130
catch (...) { \
127-
ll::error_utils::printCurrentException(lse::getSelfModInstance().getLogger()); \
131+
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
128132
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
129133
}
130134

131135
// 截获回调函数异常
132136
#define CATCH_IN_CALLBACK(callback) \
133137
catch (const Exception& e) { \
134-
ll::error_utils::printException(e, lse::getSelfModInstance().getLogger()); \
135-
lse::getSelfModInstance().getLogger().error(std::string("In callback for ") + callback); \
136-
lse::getSelfModInstance().getLogger().error("In Plugin: " + getEngineOwnData()->pluginName); \
138+
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
139+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error( \
140+
std::string("In callback for ") + callback \
141+
); \
142+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error( \
143+
"In Plugin: " + getEngineOwnData()->pluginName \
144+
); \
137145
}
138146

139147
#else
@@ -222,7 +230,7 @@ struct EnumDefineBuilder {
222230
}
223231
return arr;
224232
} catch (const std::exception&) {
225-
lse::getSelfModInstance().getLogger().error("Error in " __FUNCTION__);
233+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Error in " __FUNCTION__);
226234
}
227235
return Local<Value>();
228236
}
@@ -235,7 +243,7 @@ struct EnumDefineBuilder {
235243
}
236244
return obj;
237245
} catch (const std::exception&) {
238-
lse::getSelfModInstance().getLogger().error("Error in " __FUNCTION__);
246+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Error in " __FUNCTION__);
239247
}
240248
return Local<Value>();
241249
}
@@ -250,7 +258,7 @@ struct EnumDefineBuilder {
250258
return String::newString(magic_enum::enum_name(static_cast<Type>(args[0].asNumber().toInt32())));
251259
return Local<Value>();
252260
} catch (const std::exception&) {
253-
lse::getSelfModInstance().getLogger().error("Error in " __FUNCTION__);
261+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Error in " __FUNCTION__);
254262
}
255263
return Local<Value>();
256264
}
@@ -259,7 +267,7 @@ struct EnumDefineBuilder {
259267
try {
260268
return String::newString(typeid(Type).name() + 5);
261269
} catch (const std::exception&) {
262-
lse::getSelfModInstance().getLogger().error("Error in " __FUNCTION__);
270+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Error in " __FUNCTION__);
263271
}
264272
return Local<Value>();
265273
}
@@ -291,7 +299,11 @@ struct EnumDefineBuilder {
291299
try {
292300
return Number::newNumber(static_cast<int>(_val));
293301
} catch (const std::exception&) {
294-
lse::getSelfModInstance().getLogger().error("Error in get {}.{}", enumName, _name);
302+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error(
303+
"Error in get {}.{}",
304+
enumName,
305+
_name
306+
);
295307
}
296308
return Local<Value>();
297309
});

src/legacy/api/CommandAPI.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Local<Value> McClass::newCommand(const Arguments& args) {
260260
if (registry) {
261261
auto instance = registry->findCommand(name);
262262
if (instance) {
263-
lse::getSelfModInstance().getLogger().info(
263+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().info(
264264
"Runtime command {} already exists, changes will not beapplied except for setOverload!"_tr(name)
265265
);
266266
}
@@ -352,7 +352,7 @@ Local<Value> CommandClass::setEnum(const Arguments& args) {
352352
void onExecute(CommandOrigin const& origin, CommandOutput& output, RuntimeCommand const& runtime) {
353353
std::string commandName = runtime.getCommandName();
354354
if (localShareData->commandCallbacks.find(commandName) == localShareData->commandCallbacks.end()) {
355-
lse::getSelfModInstance().getLogger().warn(
355+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().warn(
356356
"Command {} failed to execute, is the plugin unloaded?"_tr(commandName)
357357
);
358358
return;
@@ -366,7 +366,9 @@ void onExecute(CommandOrigin const& origin, CommandOutput& output, RuntimeComman
366366

367367
auto& registeredCommands = getEngineOwnData()->plugin->registeredCommands;
368368
if (registeredCommands.find(commandName) == registeredCommands.end()) {
369-
lse::getSelfModInstance().getLogger().warn("Could not find {} in registered commands."_tr(commandName));
369+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().warn(
370+
"Could not find {} in registered commands."_tr(commandName)
371+
);
370372
return;
371373
}
372374
for (auto& info : registeredCommands[commandName]) {

src/legacy/api/CommandCompatibleAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Local<Value> McClass::regConsoleCmd(const Arguments& args) {
100100

101101
// Helper
102102
bool SendCmdOutput(const std::string& output) {
103-
lse::getSelfModInstance().getLogger().info(output);
103+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().info(output);
104104
return true;
105105
}
106106
// Helper

0 commit comments

Comments
 (0)