From ddc3964ed95d01e72229dc9af968a327cd84e56c Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Fri, 1 Oct 2004 13:21:35 +0000 Subject: - add python, missing gui - remove console (needs to be rewritten anyway) - eString -> std::string --- lib/python/python.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/python/python.cpp (limited to 'lib/python/python.cpp') diff --git a/lib/python/python.cpp b/lib/python/python.cpp new file mode 100644 index 00000000..a9ad32f6 --- /dev/null +++ b/lib/python/python.cpp @@ -0,0 +1,57 @@ +#include +#include + +extern "C" void init_enigma(); + +ePython::ePython() +{ + Py_Initialize(); + + init_enigma(); +} + +ePython::~ePython() +{ + Py_Finalize(); +} + +int ePython::execute(const std::string &pythonfile, const std::string &funcname) +{ + PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue; + + pName = PyString_FromString(pythonfile.c_str()); + + pModule = PyImport_Import(pName); + Py_DECREF(pName); + + if (pModule != NULL) + { + pDict = PyModule_GetDict(pModule); + + pFunc = PyDict_GetItemString(pDict, funcname.c_str()); + + if (pFunc && PyCallable_Check(pFunc)) + { + pArgs = PyTuple_New(0); + // implement arguments.. + pValue = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + if (pValue != NULL) + { + printf("Result of call: %ld\n", PyInt_AsLong(pValue)); + Py_DECREF(pValue); + } else + { + Py_DECREF(pModule); + PyErr_Print(); + return 1; + } + } + } else + { + if (PyErr_Occurred()) + PyErr_Print(); + return 1; + } + return 0; +} -- cgit v1.2.3