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 void ePython::call(PyObject *pFunc, PyObject *pArgs)
101 if (pFunc && PyCallable_Check(pFunc))
103 pValue = PyObject_CallObject(pFunc, pArgs);
106 // printf("Result of call: %ld\n", PyInt_AsLong(pValue));
115 PyObject *ePython::resolve(const std::string &pythonfile, const std::string &funcname)
117 PyObject *pName, *pModule, *pDict, *pFunc;
119 pName = PyString_FromString(pythonfile.c_str());
121 pModule = PyImport_Import(pName);
126 pDict = PyModule_GetDict(pModule);
127 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
130 eDebug("resolved to %p", pFunc);
134 if (PyErr_Occurred())