Skip to content

Commit 11f9e7c

Browse files
committed
fix: fix loadPlugin
1 parent 4739114 commit 11f9e7c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/lse/PluginManager.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,21 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
7474
scriptEngine.eval(baseLibContent.value());
7575

7676
// Load the plugin entry.
77-
auto pluginDir = std::filesystem::canonical(ll::plugin::getPluginsRoot() / manifest.name);
78-
auto entryPath = pluginDir / manifest.entry;
79-
auto pluginEntryContent = ll::file_utils::readFile(entryPath);
80-
if (!pluginEntryContent) {
81-
logger.error("failed to read plugin entry at {}", entryPath.string());
82-
return false;
77+
auto pluginDir = std::filesystem::canonical(ll::plugin::getPluginsRoot() / manifest.name);
78+
auto entryPath = pluginDir / manifest.entry;
79+
80+
// Try loadFile
81+
try {
82+
scriptEngine.loadFile(entryPath.u8string());
83+
} catch (const script::Exception& e) {
84+
// loadFile failed, try eval
85+
auto pluginEntryContent = ll::file_utils::readFile(entryPath);
86+
if (!pluginEntryContent) {
87+
logger.error("failed to read plugin entry at {}", entryPath.string());
88+
return false;
89+
}
90+
scriptEngine.eval(pluginEntryContent.value());
8391
}
84-
scriptEngine.eval(pluginEntryContent.value());
8592
plugin->onLoad([](ll::plugin::Plugin& plugin) { return true; });
8693
plugin->onUnload([](ll::plugin::Plugin& plugin) { return true; });
8794
plugin->onEnable([](ll::plugin::Plugin& plugin) { return true; });

0 commit comments

Comments
 (0)