#include #ifdef MOO_ENABLE_PYTHON #include #endif #include "medit-python.h" #include "mooutils/mooutils.h" #include "moopython/medit-python-init.h" #ifdef MOO_ENABLE_PYTHON struct MooPythonState { PyObject *locals; }; static PyObject * create_script_dict (const char *name) { PyObject *dict, *builtins; builtins = PyImport_ImportModule ("__builtin__"); g_return_val_if_fail (builtins != NULL, NULL); dict = PyDict_New (); PyDict_SetItemString (dict, "__builtins__", builtins); if (name) { PyObject *py_name = PyString_FromString (name); PyDict_SetItemString (dict, "__name__", py_name); Py_XDECREF (py_name); } Py_XDECREF (builtins); return dict; } static PyObject * run_string (const char *str, const char *filename, PyObject *globals, PyObject *locals) { PyObject *ret = NULL; PyObject *code; g_return_val_if_fail (str != NULL, NULL); if (!locals) locals = create_script_dict ("__script__"); else Py_INCREF ((PyObject*) locals); if (!globals) globals = locals; g_return_val_if_fail (locals != NULL, NULL); g_return_val_if_fail (globals != NULL, NULL); code = Py_CompileString (str, filename ? filename : "