@@ -31,6 +31,7 @@ namespace matplotlibcpp {
31
31
32
32
struct _interpreter {
33
33
PyObject *s_python_function_show;
34
+ PyObject *s_python_function_close;
34
35
PyObject *s_python_function_draw;
35
36
PyObject *s_python_function_pause;
36
37
PyObject *s_python_function_save;
@@ -122,6 +123,7 @@ namespace matplotlibcpp {
122
123
if (!pylabmod) { throw std::runtime_error (" Error loading module pylab!" ); }
123
124
124
125
s_python_function_show = PyObject_GetAttrString (pymod, " show" );
126
+ s_python_function_close = PyObject_GetAttrString (pymod, " close" );
125
127
s_python_function_draw = PyObject_GetAttrString (pymod, " draw" );
126
128
s_python_function_pause = PyObject_GetAttrString (pymod, " pause" );
127
129
s_python_function_figure = PyObject_GetAttrString (pymod, " figure" );
@@ -150,6 +152,7 @@ namespace matplotlibcpp {
150
152
s_python_function_xkcd = PyObject_GetAttrString (pymod, " xkcd" );
151
153
152
154
if ( !s_python_function_show
155
+ || !s_python_function_close
153
156
|| !s_python_function_draw
154
157
|| !s_python_function_pause
155
158
|| !s_python_function_figure
@@ -179,6 +182,7 @@ namespace matplotlibcpp {
179
182
) { throw std::runtime_error (" Couldn't find required function!" ); }
180
183
181
184
if ( !PyFunction_Check (s_python_function_show)
185
+ || !PyFunction_Check (s_python_function_close)
182
186
|| !PyFunction_Check (s_python_function_draw)
183
187
|| !PyFunction_Check (s_python_function_pause)
184
188
|| !PyFunction_Check (s_python_function_figure)
@@ -913,6 +917,17 @@ namespace matplotlibcpp {
913
917
Py_DECREF (res);
914
918
}
915
919
920
+ inline void close ()
921
+ {
922
+ PyObject* res = PyObject_CallObject (
923
+ detail::_interpreter::get ().s_python_function_close ,
924
+ detail::_interpreter::get ().s_python_empty_tuple );
925
+
926
+ if (!res) throw std::runtime_error (" Call to close() failed." );
927
+
928
+ Py_DECREF (res);
929
+ }
930
+
916
931
inline void xkcd () {
917
932
PyObject* res;
918
933
PyObject *kwargs = PyDict_New ();
0 commit comments