Skip to content

Commit 52a943f

Browse files
committed
refactor: removing useless pluginFileOrDirPath
optimizing stacktrace
1 parent 6ead937 commit 52a943f

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

src/legacy/api/APIHelp.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline void LOG_WRONG_ARGS_COUNT(std::string const& func = "") {
6565
#define CATCH(LOG) \
6666
catch (const Exception& e) { \
6767
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
68-
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Stacktrace: {0}", e.stacktrace()); \
68+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error(e.stacktrace()); \
6969
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
7070
return Local<Value>(); \
7171
} \
@@ -100,7 +100,7 @@ inline void LOG_WRONG_ARGS_COUNT(std::string const& func = "") {
100100
#define CATCH_C(LOG) \
101101
catch (const Exception& e) { \
102102
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
103-
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Stacktrace: {0}", e.stacktrace()); \
103+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error(e.stacktrace()); \
104104
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
105105
return nullptr; \
106106
} \
@@ -114,7 +114,7 @@ inline void LOG_WRONG_ARGS_COUNT(std::string const& func = "") {
114114
#define CATCH_S(LOG) \
115115
catch (const Exception& e) { \
116116
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
117-
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Stacktrace: {0}", e.stacktrace()); \
117+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error(e.stacktrace()); \
118118
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
119119
return; \
120120
} \
@@ -128,7 +128,7 @@ inline void LOG_WRONG_ARGS_COUNT(std::string const& func = "") {
128128
#define CATCH_WITHOUT_RETURN(LOG) \
129129
catch (const Exception& e) { \
130130
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
131-
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Stacktrace: {0}", e.stacktrace()); \
131+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error(e.stacktrace()); \
132132
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, LOG); \
133133
} \
134134
catch (...) { \
@@ -140,7 +140,7 @@ inline void LOG_WRONG_ARGS_COUNT(std::string const& func = "") {
140140
#define CATCH_IN_CALLBACK(callback) \
141141
catch (const Exception& e) { \
142142
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger()); \
143-
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Stacktrace: {0}", e.stacktrace()); \
143+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error(e.stacktrace()); \
144144
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error( \
145145
std::string("In callback for ") + callback \
146146
); \

src/legacy/engine/EngineManager.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ ScriptEngine* EngineManager::getEngine(std::string name, bool onlyLocalEngine) {
8686
for (auto& engine : globalShareData->globalEngineList) {
8787
if (onlyLocalEngine && getEngineType(engine) != LLSE_BACKEND_TYPE) continue;
8888
auto ownerData = getEngineData(engine);
89-
auto filename = ll::string_utils::u8str2str(
90-
std::filesystem::path(ll::string_utils::str2wstr(ownerData->pluginFileOrDirPath)).filename().u8string()
91-
);
92-
if (ownerData->pluginName == name || filename == name) return engine;
89+
if (ownerData->pluginName == name) return engine;
9390
}
9491
return nullptr;
9592
}

src/legacy/engine/EngineOwnData.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ struct SimpleCallbackData
3737

3838
// It is similar to ll::mod::Mod, it stores data of an engine(usually a plugin).
3939
struct EngineOwnData {
40-
// 基础信息
41-
std::string pluginName = {};
42-
std::string pluginFileOrDirPath = {};
43-
std::string engineType = LLSE_BACKEND_TYPE;
40+
// Basic information
41+
std::string pluginName = {};
42+
std::string engineType = LLSE_BACKEND_TYPE;
4443

45-
// 表单回调
44+
// Form callbacks
4645
std::map<unsigned, FormCallbackData> formCallbacks;
4746

4847
// RemoteCall Exported Functions: unordered_map<nameSpace, funcName>
@@ -74,10 +73,12 @@ struct EngineOwnData {
7473
ll::i18n::I18n i18n;
7574
std::string defaultLocaleName;
7675

77-
std::shared_ptr<lse::Plugin> plugin;
76+
std::shared_ptr<lse::Plugin> plugin;
77+
78+
// Use standalone logger in EngineOwnData instead of plugin.getLogger() for allowing modify logger title.
7879
std::shared_ptr<ll::io::Logger> logger;
7980

80-
// 玩家绑定数据
81+
// Player binding data
8182
std::unordered_map<std::string, script::Global<Value>> playerDataDB;
8283

8384
// Dynamic Call vm for NativeFFI
@@ -99,7 +100,7 @@ struct EngineOwnData {
99100
}
100101
};
101102

102-
// 引擎附加数据
103+
// Engine additional data
103104
inline std::shared_ptr<EngineOwnData> getEngineOwnData() {
104105
return std::static_pointer_cast<EngineOwnData>(EngineScope::currentEngine()->getData());
105106
}

src/lse/PluginManager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,8 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
175175
scriptEngine.eval(baseLibContent.value());
176176
#endif
177177
// Load the plugin entry.
178-
auto pluginDir = std::filesystem::canonical(ll::mod::getModsRoot() / manifest.name);
179-
auto entryPath = pluginDir / manifest.entry;
180-
getEngineOwnData()->pluginFileOrDirPath = ll::string_utils::u8str2str(entryPath.u8string());
181-
getEngineOwnData()->plugin = plugin;
178+
auto entryPath = plugin->getModDir() / manifest.entry;
179+
getEngineOwnData()->plugin = plugin;
182180
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
183181
if (!PythonHelper::loadPluginCode(
184182
&scriptEngine,

0 commit comments

Comments
 (0)