1 #include <lib/python/python.h>
2 #include <lib/base/eerror.h>
5 extern "C" void init_enigma();
8 ePyObject::ePyObject(void *ptr): m_object(ptr)
10 Py_XINCREF((PyObject*)ptr);
13 ePyObject::ePyObject(ePyObject &p)
15 m_object = p.m_object;
16 Py_XINCREF((PyObject*)m_object);
19 ePyObject::ePyObject(): m_object(0)
23 ePyObject::~ePyObject()
25 Py_XDECREF((PyObject*)m_object);
28 ePyObject &ePyObject::operator=(ePyObject &p)
30 Py_XDECREF((PyObject*)m_object);
31 m_object = p.m_object;
32 Py_XINCREF((PyObject*)m_object);
36 ePyObject &ePyObject::operator=(void *object)
38 Py_XDECREF((PyObject*)m_object);
40 Py_XINCREF((PyObject*)m_object);
57 int ePython::execute(const std::string &pythonfile, const std::string &funcname)
59 PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;
61 pName = PyString_FromString(pythonfile.c_str());
63 pModule = PyImport_Import(pName);
68 pDict = PyModule_GetDict(pModule);
70 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
72 if (pFunc && PyCallable_Check(pFunc))
74 pArgs = PyTuple_New(0);
75 // implement arguments..
76 pValue = PyObject_CallObject(pFunc, pArgs);
80 printf("Result of call: %ld\n", PyInt_AsLong(pValue));
98 int ePython::call(PyObject *pFunc, PyObject *pArgs)
102 if (pFunc && PyCallable_Check(pFunc))
104 pValue = PyObject_CallObject(pFunc, pArgs);
107 if (PyInt_Check(pValue))
108 res = PyInt_AsLong(pValue);
120 PyObject *ePython::resolve(const std::string &pythonfile, const std::string &funcname)
122 PyObject *pName, *pModule, *pDict, *pFunc;
124 pName = PyString_FromString(pythonfile.c_str());
126 pModule = PyImport_Import(pName);
131 pDict = PyModule_GetDict(pModule);
132 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
135 eDebug("resolved to %p", pFunc);
139 if (PyErr_Occurred())