diff options
| author | Felix Domke <tmbinc@elitedvb.net> | 2004-10-01 13:21:35 +0000 |
|---|---|---|
| committer | Felix Domke <tmbinc@elitedvb.net> | 2004-10-01 13:21:35 +0000 |
| commit | ddc3964ed95d01e72229dc9af968a327cd84e56c (patch) | |
| tree | 93e6694c639db3d188f5b2868f6b2b2951d21d60 /lib/python/python.cpp | |
| parent | 1aeefd997cc362c3b37c1587c5f08891b35c3a75 (diff) | |
| download | enigma2-ddc3964ed95d01e72229dc9af968a327cd84e56c.tar.gz enigma2-ddc3964ed95d01e72229dc9af968a327cd84e56c.zip | |
- add python, missing gui
- remove console (needs to be rewritten anyway)
- eString -> std::string
Diffstat (limited to 'lib/python/python.cpp')
| -rw-r--r-- | lib/python/python.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
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 <lib/python/python.h> +#include <Python.h> + +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; +} |
