1 #include <lib/python/python.h>
2 #include <lib/base/eerror.h>
5 #define _POSIX_C_SOURCE 200112L
8 extern "C" void init_enigma();
14 eDebug("create %p", this);
19 eDebug("destroy %p", this);
23 ePyObject::ePyObject(void *ptr): m_object(ptr)
25 Py_XINCREF((PyObject*)ptr);
28 ePyObject::ePyObject(ePyObject &p)
30 m_object = p.m_object;
31 Py_XINCREF((PyObject*)m_object);
34 ePyObject::ePyObject(): m_object(0)
38 ePyObject::~ePyObject()
40 Py_XDECREF((PyObject*)m_object);
43 ePyObject &ePyObject::operator=(ePyObject &p)
45 Py_XDECREF((PyObject*)m_object);
46 m_object = p.m_object;
47 Py_XINCREF((PyObject*)m_object);
51 ePyObject &ePyObject::operator=(void *object)
53 Py_XDECREF((PyObject*)m_object);
55 Py_XINCREF((PyObject*)m_object);
62 // Py_VerboseFlag = 1;
74 int ePython::execute(const std::string &pythonfile, const std::string &funcname)
76 PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;
78 pName = PyString_FromString(pythonfile.c_str());
80 pModule = PyImport_Import(pName);
85 pDict = PyModule_GetDict(pModule);
87 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
89 if (pFunc && PyCallable_Check(pFunc))
91 pArgs = PyTuple_New(0);
92 // implement arguments..
93 pValue = PyObject_CallObject(pFunc, pArgs);
97 printf("Result of call: %ld\n", PyInt_AsLong(pValue));
108 if (PyErr_Occurred())
115 int ePython::call(PyObject *pFunc, PyObject *pArgs)
119 if (pFunc && PyCallable_Check(pFunc))
121 pValue = PyObject_CallObject(pFunc, pArgs);
124 if (PyInt_Check(pValue))
125 res = PyInt_AsLong(pValue);
137 PyObject *ePython::resolve(const std::string &pythonfile, const std::string &funcname)
139 PyObject *pName, *pModule, *pDict, *pFunc;
141 pName = PyString_FromString(pythonfile.c_str());
143 pModule = PyImport_Import(pName);
148 pDict = PyModule_GetDict(pModule);
149 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
155 if (PyErr_Occurred())