Skip to content

Commit

Permalink
refactor: refactoring Entry
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Jan 9, 2025
1 parent d1695d1 commit 65c7ed2
Show file tree
Hide file tree
Showing 36 changed files with 482 additions and 340 deletions.
2 changes: 1 addition & 1 deletion src/legacy/api/APIHelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ Local<Value> JsonToValue(std::string jsonStr) {
auto j = ordered_json::parse(jsonStr, nullptr, true, true);
return JsonToValue(j);
} catch (const ordered_json::exception& e) {
lse::getSelfModInstance().getLogger().warn(
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().warn(
"{}{}",
"JSON parse error"_tr(),
ll::string_utils::tou8str(e.what())
Expand Down
50 changes: 31 additions & 19 deletions src/legacy/api/APIHelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ std::string ValueKindToString(const ValueKind& kind);
// 输出脚本调用堆栈,API名称,以及插件名
inline void LOG_ERROR_WITH_SCRIPT_INFO(std::string const& func = "", std::string const& msg = "") {
auto e = script::Exception(msg);
lse::getSelfModInstance().getLogger().error("script::Exception: {0}\n{1}", e.message(), e.stacktrace());
lse::getSelfModInstance().getLogger().error("In API: " + func);
lse::getSelfModInstance().getLogger().error("In Plugin: " + getEngineOwnData()->pluginName);
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error(
"script::Exception: {0}\n{1}",
e.message(),
e.stacktrace()
);
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("In API: " + func);
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("In Plugin: " + getEngineOwnData()->pluginName);
}

// 参数类型错误输出
Expand Down Expand Up @@ -60,12 +64,12 @@ inline void LOG_WRONG_ARGS_COUNT(std::string const& func = "") {
// 截获引擎异常
#define CATCH(LOG) \
catch (const Exception& e) { \
ll::error_utils::printException(e, lse::getSelfModInstance().getLogger()); \
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
return Local<Value>(); \
} \
catch (...) { \
ll::error_utils::printCurrentException(lse::getSelfModInstance().getLogger()); \
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
return Local<Value>(); \
}
Expand Down Expand Up @@ -94,46 +98,50 @@ inline void LOG_WRONG_ARGS_COUNT(std::string const& func = "") {
// 截获引擎异常_Constructor
#define CATCH_C(LOG) \
catch (const Exception& e) { \
ll::error_utils::printException(e, lse::getSelfModInstance().getLogger()); \
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
return nullptr; \
} \
catch (...) { \
ll::error_utils::printCurrentException(lse::getSelfModInstance().getLogger()); \
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
return nullptr; \
}

// 截获引擎异常_Setter
#define CATCH_S(LOG) \
catch (const Exception& e) { \
ll::error_utils::printException(e, lse::getSelfModInstance().getLogger()); \
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
return; \
} \
catch (...) { \
ll::error_utils::printCurrentException(lse::getSelfModInstance().getLogger()); \
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
return; \
}

// 截获引擎异常_Constructor
#define CATCH_WITHOUT_RETURN(LOG) \
catch (const Exception& e) { \
ll::error_utils::printException(e, lse::getSelfModInstance().getLogger()); \
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
} \
catch (...) { \
ll::error_utils::printCurrentException(lse::getSelfModInstance().getLogger()); \
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
}

// 截获回调函数异常
#define CATCH_IN_CALLBACK(callback) \
catch (const Exception& e) { \
ll::error_utils::printException(e, lse::getSelfModInstance().getLogger()); \
lse::getSelfModInstance().getLogger().error(std::string("In callback for ") + callback); \
lse::getSelfModInstance().getLogger().error("In Plugin: " + getEngineOwnData()->pluginName); \
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error( \
std::string("In callback for ") + callback \
); \
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error( \
"In Plugin: " + getEngineOwnData()->pluginName \
); \
}

#else
Expand Down Expand Up @@ -222,7 +230,7 @@ struct EnumDefineBuilder {
}
return arr;
} catch (const std::exception&) {
lse::getSelfModInstance().getLogger().error("Error in " __FUNCTION__);
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Error in " __FUNCTION__);
}
return Local<Value>();
}
Expand All @@ -235,7 +243,7 @@ struct EnumDefineBuilder {
}
return obj;
} catch (const std::exception&) {
lse::getSelfModInstance().getLogger().error("Error in " __FUNCTION__);
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Error in " __FUNCTION__);
}
return Local<Value>();
}
Expand All @@ -250,7 +258,7 @@ struct EnumDefineBuilder {
return String::newString(magic_enum::enum_name(static_cast<Type>(args[0].asNumber().toInt32())));
return Local<Value>();
} catch (const std::exception&) {
lse::getSelfModInstance().getLogger().error("Error in " __FUNCTION__);
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Error in " __FUNCTION__);
}
return Local<Value>();
}
Expand All @@ -259,7 +267,7 @@ struct EnumDefineBuilder {
try {
return String::newString(typeid(Type).name() + 5);
} catch (const std::exception&) {
lse::getSelfModInstance().getLogger().error("Error in " __FUNCTION__);
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Error in " __FUNCTION__);
}
return Local<Value>();
}
Expand Down Expand Up @@ -291,7 +299,11 @@ struct EnumDefineBuilder {
try {
return Number::newNumber(static_cast<int>(_val));
} catch (const std::exception&) {
lse::getSelfModInstance().getLogger().error("Error in get {}.{}", enumName, _name);
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error(
"Error in get {}.{}",
enumName,
_name
);
}
return Local<Value>();
});
Expand Down
8 changes: 5 additions & 3 deletions src/legacy/api/CommandAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Local<Value> McClass::newCommand(const Arguments& args) {
if (registry) {
auto instance = registry->findCommand(name);
if (instance) {
lse::getSelfModInstance().getLogger().info(
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().info(
"Runtime command {} already exists, changes will not beapplied except for setOverload!"_tr(name)
);
}
Expand Down Expand Up @@ -352,7 +352,7 @@ Local<Value> CommandClass::setEnum(const Arguments& args) {
void onExecute(CommandOrigin const& origin, CommandOutput& output, RuntimeCommand const& runtime) {
std::string commandName = runtime.getCommandName();
if (localShareData->commandCallbacks.find(commandName) == localShareData->commandCallbacks.end()) {
lse::getSelfModInstance().getLogger().warn(
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().warn(
"Command {} failed to execute, is the plugin unloaded?"_tr(commandName)
);
return;
Expand All @@ -366,7 +366,9 @@ void onExecute(CommandOrigin const& origin, CommandOutput& output, RuntimeComman

auto& registeredCommands = getEngineOwnData()->plugin->registeredCommands;
if (registeredCommands.find(commandName) == registeredCommands.end()) {
lse::getSelfModInstance().getLogger().warn("Could not find {} in registered commands."_tr(commandName));
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().warn(
"Could not find {} in registered commands."_tr(commandName)
);
return;
}
for (auto& info : registeredCommands[commandName]) {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/CommandCompatibleAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Local<Value> McClass::regConsoleCmd(const Arguments& args) {

// Helper
bool SendCmdOutput(const std::string& output) {
lse::getSelfModInstance().getLogger().info(output);
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().info(output);
return true;
}
// Helper
Expand Down
Loading

0 comments on commit 65c7ed2

Please sign in to comment.