plugin_manager.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include <memory>
  5. #include <unordered_map>
  6. #include <filesystem>
  7. namespace lumacs {
  8. // Forward declarations
  9. class EditorCore;
  10. class LuaApi;
  11. /// @brief Represents a loaded Lua plugin.
  12. struct Plugin {
  13. std::string name;
  14. std::filesystem::path path;
  15. // Potentially add more state like loaded status, config table, etc.
  16. };
  17. /// @brief Manages the discovery, loading, and unloading of Lua plugins.
  18. class PluginManager {
  19. public:
  20. explicit PluginManager(EditorCore& core, LuaApi& lua_api);
  21. /// @brief Discovers Lua plugin files in specified directories.
  22. /// @param plugin_dirs A list of directories to search for plugins.
  23. void discover_plugins(const std::vector<std::filesystem::path>& plugin_dirs);
  24. /// @brief Loads a specific plugin by name.
  25. /// @param name The name of the plugin to load (e.g., "my_plugin").
  26. /// @return True if the plugin was loaded successfully, false otherwise.
  27. bool load_plugin(const std::string& name);
  28. /// @brief Unloads a specific plugin by name.
  29. /// @param name The name of the plugin to unload.
  30. /// @return True if the plugin was unloaded successfully, false otherwise.
  31. bool unload_plugin(const std::string& name);
  32. /// @brief Gets a list of all discovered plugin names.
  33. std::vector<std::string> get_discovered_plugins() const;
  34. /// @brief Gets a list of currently loaded plugin names.
  35. std::vector<std::string> get_loaded_plugins() const;
  36. private:
  37. [[maybe_unused]] EditorCore& core_; // Reserved for future plugin integration
  38. LuaApi& lua_api_;
  39. std::unordered_map<std::string, std::filesystem::path> discovered_plugins_;
  40. std::unordered_map<std::string, Plugin> loaded_plugins_;
  41. /// @brief Helper to execute a plugin's `on_load` function.
  42. void execute_on_load(const Plugin& plugin);
  43. /// @brief Helper to execute a plugin's `on_unload` function.
  44. void execute_on_unload(const Plugin& plugin);
  45. };
  46. } // namespace lumacs