Added InterpreterSingleton::getValue(...) function.

This commit is contained in:
Eivind Kvedalen
2015-02-03 00:32:00 +01:00
committed by wmayer
parent 524e982b5e
commit 75dab66916
2 changed files with 24 additions and 0 deletions

View File

@@ -496,6 +496,28 @@ void InterpreterSingleton::runMethod(PyObject *pobject, const char *method,
}
}
PyObject * InterpreterSingleton::getValue(const char * key, const char * result_var)
{
PyObject *module, *dict, *presult; /* "exec code in d, d" */
PyGILStateLocker locker;
module = PP_Load_Module("__main__"); /* get module, init python */
if (module == NULL)
throw PyException(); /* not incref'd */
dict = PyModule_GetDict(module); /* get dict namespace */
if (dict == NULL)
throw PyException(); /* not incref'd */
presult = PyRun_String(key, Py_file_input, dict, dict); /* eval direct */
if (!presult) {
throw PyException();
}
Py_DECREF(presult);
return PyObject_GetAttrString(module, result_var);
}
void InterpreterSingleton::dbgObserveFile(const char* sFileName)
{
if (sFileName)