From 4739114551fdca04fa9846ef9c1d838113951a9d Mon Sep 17 00:00:00 2001 From: ShrBox Date: Fri, 23 Feb 2024 20:47:14 +0800 Subject: [PATCH] fix: fix error in unload --- src/lse/Plugin.h | 6 +++++- src/lse/PluginManager.cpp | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lse/Plugin.h b/src/lse/Plugin.h index 23bc133b..e155be52 100644 --- a/src/lse/Plugin.h +++ b/src/lse/Plugin.h @@ -1,5 +1,7 @@ #pragma once +#include "PluginManager.h" + #include #include @@ -8,6 +10,8 @@ namespace lse { class Plugin : public ll::plugin::Plugin { public: Plugin(const ll::plugin::Manifest& manifest); -}; +private: + friend PluginManager; +}; } // namespace lse diff --git a/src/lse/PluginManager.cpp b/src/lse/PluginManager.cpp index 85dab0c7..2e4c5ab1 100644 --- a/src/lse/PluginManager.cpp +++ b/src/lse/PluginManager.cpp @@ -51,6 +51,7 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool { } auto& scriptEngine = *EngineManager::newEngine(manifest.name); + auto plugin = std::make_shared(manifest); try { script::EngineScope engineScope(scriptEngine); @@ -81,7 +82,10 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool { return false; } 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; }); + plugin->onDisable([](ll::plugin::Plugin& plugin) { return true; }); } catch (const std::exception& e) { LLSERemoveTimeTaskData(&scriptEngine); LLSERemoveAllEventListeners(&scriptEngine); @@ -93,10 +97,9 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool { EngineManager::unregisterEngine(&scriptEngine); - // throw; + return false; } - auto plugin = std::make_shared(manifest); if (!addPlugin(manifest.name, plugin)) { logger.error("failed to register plugin {}", manifest.name); return false;