Skip to content

Commit

Permalink
fix: fix loadPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Feb 23, 2024
1 parent 4739114 commit 11f9e7c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/lse/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,21 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
scriptEngine.eval(baseLibContent.value());

// Load the plugin entry.
auto pluginDir = std::filesystem::canonical(ll::plugin::getPluginsRoot() / manifest.name);
auto entryPath = pluginDir / manifest.entry;
auto pluginEntryContent = ll::file_utils::readFile(entryPath);
if (!pluginEntryContent) {
logger.error("failed to read plugin entry at {}", entryPath.string());
return false;
auto pluginDir = std::filesystem::canonical(ll::plugin::getPluginsRoot() / manifest.name);
auto entryPath = pluginDir / manifest.entry;

// Try loadFile
try {
scriptEngine.loadFile(entryPath.u8string());
} catch (const script::Exception& e) {
// loadFile failed, try eval
auto pluginEntryContent = ll::file_utils::readFile(entryPath);
if (!pluginEntryContent) {
logger.error("failed to read plugin entry at {}", entryPath.string());
return false;
}
scriptEngine.eval(pluginEntryContent.value());
}
scriptEngine.eval(pluginEntryContent.value());
plugin->onLoad([](ll::plugin::Plugin& plugin) { return true; });
plugin->onUnload([](ll::plugin::Plugin& plugin) { return true; });
plugin->onEnable([](ll::plugin::Plugin& plugin) { return true; });
Expand Down

0 comments on commit 11f9e7c

Please sign in to comment.