diff --git a/.gitignore b/.gitignore index e3fbd98..fb40ccb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build node_modules +.vscode diff --git a/binding.gyp b/binding.gyp index fe4edd9..bcc0dc2 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,6 +3,12 @@ { "target_name": "matplotlib", "sources": [ "src/matplotlib.cc" ], + "include_dirs": [ + " #include +#ifdef linux + #include +#endif + #if PY_MAJOR_VERSION >= 3 #define PyString_FromString PyUnicode_FromString #endif +#ifndef WITHOUT_NUMPY + #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION + #include +#endif // WITHOUT_NUMPY + namespace plt { struct interpreter { public: @@ -36,6 +45,22 @@ namespace plt { return context; } private: +#ifndef WITHOUT_NUMPY +# if PY_MAJOR_VERSION >= 3 + + void *import_numpy() { + import_array(); // initialize C-API + return NULL; + } + +# else + + void import_numpy() { + import_array(); // initialize C-API + } + +# endif +#endif interpreter() { #if PY_MAJOR_VERSION >= 3 wchar_t name[] = L"matplotnode"; @@ -43,8 +68,21 @@ namespace plt { char name[] = "matplotnode"; #endif Py_SetProgramName(name); + +#ifdef linux +#if PY_MAJOR_VERSION >= 3 + dlopen("libpython3.so", RTLD_LAZY | RTLD_GLOBAL); +#else + dlopen("libpython2.7.so", RTLD_LAZY | RTLD_GLOBAL); +#endif +#endif + Py_Initialize(); +#ifndef WITHOUT_NUMPY + import_numpy(); // initialize numpy C-API +#endif + PyObject *matplotlibname = PyString_FromString("matplotlib"); PyObject* matplotlib = PyImport_Import(matplotlibname); Py_DECREF(matplotlibname);