Added InterpreterSingleton::getValue(...) function.
This commit is contained in:
parent
524e982b5e
commit
75dab66916
|
@ -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)
|
void InterpreterSingleton::dbgObserveFile(const char* sFileName)
|
||||||
{
|
{
|
||||||
if (sFileName)
|
if (sFileName)
|
||||||
|
|
|
@ -242,6 +242,8 @@ public:
|
||||||
static const std::string strToPython(const std::string &Str){return strToPython(Str.c_str());}
|
static const std::string strToPython(const std::string &Str){return strToPython(Str.c_str());}
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
PyObject *getValue(const char *key, const char *result_var);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// singleton
|
// singleton
|
||||||
static InterpreterSingleton *_pcSingelton;
|
static InterpreterSingleton *_pcSingelton;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user