Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
node_modules
.vscode
8 changes: 7 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
{
"target_name": "matplotlib",
"sources": [ "src/matplotlib.cc" ],
"include_dirs": [
"<!(python -c 'import numpy; print(numpy.get_include())')"
],
"libraries": [
"-ldl"
],
"conditions": [
['OS=="mac"', {
"xcode_settings": {
Expand All @@ -18,7 +24,7 @@
"<!(python-config --cflags)"
],
"libraries": [
"<!(python-config --libs)"
"<!(python-config --libs)",
]
}]
]
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matplotnode",
"version": "0.3.1",
"version": "0.3.2",
"description": "C++ bindings for Node.js exposing a subset of matplotlib's functionality through the CPython API.",
"main": "src/matplotlib.js",
"scripts": {
Expand Down
38 changes: 38 additions & 0 deletions src/matplotlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
#include <string>
#include <Python.h>

#ifdef linux
#include <dlfcn.h>
#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 <numpy/arrayobject.h>
#endif // WITHOUT_NUMPY

namespace plt {
struct interpreter {
public:
Expand Down Expand Up @@ -36,15 +45,44 @@ 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";
#else
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);
Expand Down