Skip to content

Commit 5ceb498

Browse files
committed
fix: fix logger while plugin loading
1 parent a7490e1 commit 5ceb498

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

src/legacy/api/LoggerAPI.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ std::string& StrReplace(std::string& str, const std::string& to_replaced, const
5252
void inline LogDataHelper(LogLevel level, const Arguments& args) {
5353
std::string res;
5454
for (int i = 0; i < args.size(); ++i) res += ValueToString(args[i]);
55-
getEngineOwnData()->getModInstance()->getLogger().log(level, res);
55+
getEngineOwnData()->plugin->getLogger().log(level, res);
5656
}
5757

5858
Local<Value> LoggerClass::log(const Arguments& args) {
@@ -138,12 +138,12 @@ Local<Value> LoggerClass::setConsole(const Arguments& args) {
138138

139139
try {
140140
if (args.size() >= 2) {
141-
getEngineOwnData()->getModInstance()->getLogger().getSink(0)->setFlushLevel(
141+
getEngineOwnData()->plugin->getLogger().getSink(0)->setFlushLevel(
142142
static_cast<ll::io::LogLevel>(args[1].asNumber().toInt32() + 1)
143143
); // See LSE's definition https://legacy-script-engine.levimc.org/apis/ScriptAPI/Logger/
144144
}
145145
if (!args[0].asBoolean().value()) {
146-
getEngineOwnData()->getModInstance()->getLogger().getSink(0)->setFlushLevel(ll::io::LogLevel::Off);
146+
getEngineOwnData()->plugin->getLogger().getSink(0)->setFlushLevel(ll::io::LogLevel::Off);
147147
}
148148
return Boolean::newBoolean(true);
149149
}
@@ -169,7 +169,7 @@ Local<Value> LoggerClass::setFile(const Arguments& args) {
169169
if (args.size() >= 2) {
170170
sink->setFlushLevel(static_cast<LogLevel>(args[1].asNumber().toInt32() + 1));
171171
}
172-
return Boolean::newBoolean(getEngineOwnData()->getModInstance()->getLogger().addSink(sink));
172+
return Boolean::newBoolean(getEngineOwnData()->plugin->getLogger().addSink(sink));
173173
}
174174
CATCH("Fail in LoggerSetFile!")
175175
}
@@ -185,7 +185,7 @@ Local<Value> LoggerClass::setPlayer(const Arguments& args) {
185185
if (args.size() >= 2) {
186186
sink->setFlushLevel(static_cast<LogLevel>(args[1].asNumber().toInt32() + 1));
187187
}
188-
return Boolean::newBoolean(getEngineOwnData()->getModInstance()->getLogger().addSink(sink));
188+
return Boolean::newBoolean(getEngineOwnData()->plugin->getLogger().addSink(sink));
189189
}
190190
CATCH("Fail in LoggerSetPlayer!")
191191
}
@@ -196,7 +196,7 @@ Local<Value> LoggerClass::setLogLevel(const Arguments& args) {
196196

197197
try {
198198
auto conf = getEngineOwnData();
199-
conf->getModInstance()->getLogger().setLevel(static_cast<LogLevel>(args[0].asNumber().toInt32() + 1));
199+
conf->plugin->getLogger().setLevel(static_cast<LogLevel>(args[0].asNumber().toInt32() + 1));
200200
return Boolean::newBoolean(true);
201201
}
202202
CATCH("Fail in SetLogLevel!")

src/legacy/api/ScriptAPI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Local<Value> Log(const Arguments& args) {
2424
std::ostringstream sout;
2525
for (int i = 0; i < args.size(); ++i) PrintValue(sout, args[i]);
2626
sout << std::endl;
27-
getEngineOwnData()->getModInstance()->getLogger().info(sout.str());
27+
getEngineOwnData()->plugin->getLogger().info(sout.str());
2828
return Boolean::newBoolean(true);
2929
}
3030
CATCH("Fail in Log!");
@@ -89,7 +89,7 @@ Local<Value> ColorLog(const Arguments& args) {
8989
sout << prefix;
9090
for (int i = 1; i < args.size(); ++i) PrintValue(sout, args[i]);
9191
sout << "\x1b[0m" << std::endl;
92-
getEngineOwnData()->getModInstance()->getLogger().info(sout.str());
92+
getEngineOwnData()->plugin->getLogger().info(sout.str());
9393
return Boolean::newBoolean(true);
9494
}
9595
CATCH("Fail in Log!");

src/legacy/engine/EngineOwnData.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ll/api/mod/Mod.h"
66
#include "lse/Entry.h"
77
#include "utils/UsingScriptX.h"
8+
#include "lse/Plugin.h"
89

910
#include <ll/api/Expected.h>
1011
#include <ll/api/i18n/I18n.h>
@@ -72,6 +73,7 @@ struct EngineOwnData {
7273

7374
// I18nAPI
7475
std::shared_ptr<ll::i18n::I18n> i18n = nullptr;
76+
std::shared_ptr<lse::Plugin> plugin;
7577

7678
// 玩家绑定数据
7779
std::unordered_map<std::string, script::Global<Value>> playerDataDB;
@@ -93,10 +95,6 @@ struct EngineOwnData {
9395
dynamicCallVM = dcNewCallVM(4096);
9496
dcMode(dynamicCallVM, DC_CALL_C_DEFAULT);
9597
}
96-
97-
[[nodiscard]] inline std::shared_ptr<ll::mod::Mod> getModInstance() const {
98-
return lse::getPluginManager().getMod(pluginName);
99-
}
10098
};
10199

102100
// 引擎附加数据

src/lse/PluginManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
171171
auto pluginDir = std::filesystem::canonical(ll::mod::getModsRoot() / manifest.name);
172172
auto entryPath = pluginDir / manifest.entry;
173173
getEngineOwnData()->pluginFileOrDirPath = ll::string_utils::u8str2str(entryPath.u8string());
174+
getEngineOwnData()->plugin = plugin;
174175
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
175176
if (!PythonHelper::loadPluginCode(
176177
&scriptEngine,

0 commit comments

Comments
 (0)