1 #include <lib/python/python.h>
2 #include <lib/base/eerror.h>
5 #define _POSIX_C_SOURCE 200112L
8 extern "C" void init_enigma();
9 extern void bsodFatal();
15 eDebug("create %p", this);
20 eDebug("destroy %p", this);
24 ePyObject::ePyObject(void *ptr): m_object(ptr)
26 Py_XINCREF((PyObject*)ptr);
29 ePyObject::ePyObject(ePyObject &p)
31 m_object = p.m_object;
32 Py_XINCREF((PyObject*)m_object);
35 ePyObject::ePyObject(): m_object(0)
39 ePyObject::~ePyObject()
41 Py_XDECREF((PyObject*)m_object);
44 ePyObject &ePyObject::operator=(ePyObject &p)
46 Py_XDECREF((PyObject*)m_object);
47 m_object = p.m_object;
48 Py_XINCREF((PyObject*)m_object);
52 ePyObject &ePyObject::operator=(void *object)
54 Py_XDECREF((PyObject*)m_object);
56 Py_XINCREF((PyObject*)m_object);
63 // Py_VerboseFlag = 1;
65 // Py_OptimizeFlag = 1;
77 int ePython::execute(const std::string &pythonfile, const std::string &funcname)
79 PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;
80 pName = PyString_FromString(pythonfile.c_str());
82 pModule = PyImport_Import(pName);
87 pDict = PyModule_GetDict(pModule);
89 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
91 if (pFunc && PyCallable_Check(pFunc))
93 pArgs = PyTuple_New(0);
94 // implement arguments..
95 pValue = PyObject_CallObject(pFunc, pArgs);
99 printf("Result of call: %ld\n", PyInt_AsLong(pValue));
110 if (PyErr_Occurred())
117 int ePython::call(PyObject *pFunc, PyObject *pArgs)
121 if (pFunc && PyCallable_Check(pFunc))
123 pValue = PyObject_CallObject(pFunc, pArgs);
126 if (PyInt_Check(pValue))
127 res = PyInt_AsLong(pValue);
140 PyObject *ePython::resolve(const std::string &pythonfile, const std::string &funcname)
142 PyObject *pName, *pModule, *pDict, *pFunc;
144 pName = PyString_FromString(pythonfile.c_str());
146 pModule = PyImport_Import(pName);
151 pDict = PyModule_GetDict(pModule);
152 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
158 if (PyErr_Occurred())