|
|
|
|
@ -23,6 +23,25 @@ Plugins::~Plugins() {
|
|
|
|
|
py::finalize_interpreter(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Plugins::init_hook() { |
|
|
|
|
for(auto &module_name : loaded_modules) { |
|
|
|
|
auto module = py::module(py::handle(PyImport_GetModule(py::str(module_name.c_str()).ptr())), false); |
|
|
|
|
if(py::hasattr(module, "init_hook")) { |
|
|
|
|
py::object obj = module.attr("init_hook"); |
|
|
|
|
if(py::isinstance<py::function>(obj)) { |
|
|
|
|
py::function func(obj); |
|
|
|
|
try { |
|
|
|
|
func(); |
|
|
|
|
} |
|
|
|
|
catch(const py::error_already_set &err) { |
|
|
|
|
std::cerr << err.what() << std::endl; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Plugins::load() { |
|
|
|
|
const auto &plugin_path = Config::get().plugins.path; |
|
|
|
|
|
|
|
|
|
@ -49,6 +68,7 @@ void Plugins::load() {
|
|
|
|
|
if((is_directory && !is_pycache) || has_py_extension) { |
|
|
|
|
try { |
|
|
|
|
auto module = py::module::import(module_name.c_str()); |
|
|
|
|
loaded_modules.push_back(module_name); |
|
|
|
|
} |
|
|
|
|
catch(py::error_already_set &error) { |
|
|
|
|
std::cerr << "Error loading plugin `" << module_name << "`:\n" |
|
|
|
|
|