mirror of https://gitlab.com/cppit/jucipp
7 changed files with 20 additions and 56 deletions
@ -1,14 +1,14 @@ |
|||||||
#pragma once |
#pragma once |
||||||
#include "python_interpreter.h" |
#include "python_bind.h" |
||||||
#include <pybind11/embed.h> |
#include <pybind11/embed.h> |
||||||
|
|
||||||
class __attribute__((visibility("default"))) |
class __attribute__((visibility("default"))) |
||||||
Plugins { |
Plugins { |
||||||
public: |
public: |
||||||
Plugins(); |
Plugins(); |
||||||
|
~Plugins(); |
||||||
void load(); |
void load(); |
||||||
|
|
||||||
private: |
private: |
||||||
py::detail::embedded_module jucipp_module; |
py::detail::embedded_module jucipp_module; |
||||||
Python::Interpreter interpreter; |
|
||||||
}; |
}; |
||||||
|
|||||||
@ -1,39 +0,0 @@ |
|||||||
#include "python_interpreter.h" |
|
||||||
|
|
||||||
pybind11::module Python::Interpreter::add_module(const std::string &module_name) { |
|
||||||
return pybind11::reinterpret_borrow<pybind11::module>(PyImport_AddModule(module_name.c_str())); |
|
||||||
} |
|
||||||
|
|
||||||
pybind11::object Python::Interpreter::error() { |
|
||||||
return pybind11::reinterpret_borrow<pybind11::object>(PyErr_Occurred()); |
|
||||||
} |
|
||||||
|
|
||||||
pybind11::module Python::Interpreter::reload_module(pybind11::module &module) { |
|
||||||
auto reload = pybind11::reinterpret_steal<pybind11::module>(PyImport_ReloadModule(module.ptr())); |
|
||||||
if(!reload) { |
|
||||||
throw pybind11::error_already_set(); |
|
||||||
} |
|
||||||
return reload; |
|
||||||
} |
|
||||||
|
|
||||||
#include <pybind11/embed.h> |
|
||||||
#include <iostream> |
|
||||||
|
|
||||||
Python::Interpreter::~Interpreter() { |
|
||||||
if (error()){ |
|
||||||
std::cout << py::error_already_set().what() << std::endl; |
|
||||||
} |
|
||||||
py::finalize_interpreter(); |
|
||||||
} |
|
||||||
|
|
||||||
Python::Interpreter::Interpreter() { |
|
||||||
#ifdef PYTHON_HOME_DIR |
|
||||||
#ifdef _WIN32 |
|
||||||
const std::wstring python_home(PYTHON_HOME_DIR); |
|
||||||
const std::wstring python_path(python_home + L";" + python_home + L"\\lib-dynload;" + python_home + L"\\site-packages" ); |
|
||||||
Py_SetPythonHome(python_home.c_str()); |
|
||||||
Py_SetPath(python_path.c_str()); |
|
||||||
#endif |
|
||||||
#endif |
|
||||||
py::initialize_interpreter(); |
|
||||||
} |
|
||||||
@ -1,13 +0,0 @@ |
|||||||
#pragma once |
|
||||||
#include "python_bind.h" |
|
||||||
|
|
||||||
namespace Python { |
|
||||||
class Interpreter { |
|
||||||
public: |
|
||||||
pybind11::module static add_module(const std::string &module_name); |
|
||||||
pybind11::module static reload_module(pybind11::module &module); |
|
||||||
pybind11::object static error(); |
|
||||||
~Interpreter(); |
|
||||||
Interpreter(); |
|
||||||
}; |
|
||||||
}; // namespace Python
|
|
||||||
Loading…
Reference in new issue