1 #include <lib/python/python.h>
2 #include <lib/base/eerror.h>
5 extern "C" void init_enigma();
11 eDebug("create %p", this);
16 eDebug("destroy %p", this);
20 ePyObject::ePyObject(void *ptr): m_object(ptr)
22 Py_XINCREF((PyObject*)ptr);
25 ePyObject::ePyObject(ePyObject &p)
27 m_object = p.m_object;
28 Py_XINCREF((PyObject*)m_object);
31 ePyObject::ePyObject(): m_object(0)
35 ePyObject::~ePyObject()
37 Py_XDECREF((PyObject*)m_object);
40 ePyObject &ePyObject::operator=(ePyObject &p)
42 Py_XDECREF((PyObject*)m_object);
43 m_object = p.m_object;
44 Py_XINCREF((PyObject*)m_object);
48 ePyObject &ePyObject::operator=(void *object)
50 Py_XDECREF((PyObject*)m_object);
52 Py_XINCREF((PyObject*)m_object);
69 int ePython::execute(const std::string &pythonfile, const std::string &funcname)
71 PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;
73 pName = PyString_FromString(pythonfile.c_str());
75 pModule = PyImport_Import(pName);
80 pDict = PyModule_GetDict(pModule);
82 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
84 if (pFunc && PyCallable_Check(pFunc))
86 pArgs = PyTuple_New(0);
87 // implement arguments..
88 pValue = PyObject_CallObject(pFunc, pArgs);
92 printf("Result of call: %ld\n", PyInt_AsLong(pValue));
103 if (PyErr_Occurred())
110 int ePython::call(PyObject *pFunc, PyObject *pArgs)
114 if (pFunc && PyCallable_Check(pFunc))
116 pValue = PyObject_CallObject(pFunc, pArgs);
119 if (PyInt_Check(pValue))
120 res = PyInt_AsLong(pValue);
132 PyObject *ePython::resolve(const std::string &pythonfile, const std::string &funcname)
134 PyObject *pName, *pModule, *pDict, *pFunc;
136 pName = PyString_FromString(pythonfile.c_str());
138 pModule = PyImport_Import(pName);
143 pDict = PyModule_GetDict(pModule);
144 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
150 if (PyErr_Occurred())