-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpy_handler.cpp
More file actions
37 lines (29 loc) · 845 Bytes
/
py_handler.cpp
File metadata and controls
37 lines (29 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "py_handler.hpp"
#define PY_SSIZE_T_CLEAN
#include <Python.h>
py_handler::py_handler()
{
PyStatus status;
PyConfig config;
PyConfig_InitPythonConfig(&config);
config._init_main = 0;
status = Py_InitializeFromConfig(&config);
PyConfig_Clear(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
status = _Py_InitializeMain();
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
//more module locations in future
std::filesystem::path cwd = std::filesystem::current_path() / "music";
std::string fullPath = cwd.string();
std::string exec = "import sys\nsys.path.append('" + fullPath + "')";
PyRun_SimpleString(exec.c_str());
LOG("PyHandler initialized");
}
py_handler::~py_handler()
{
Py_Finalize();
}