Skip to content

Commit

Permalink
Added InterpreterSingleton::getValue(...) function.
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindkv authored and wwmayer committed Feb 13, 2015
1 parent 524e982 commit 75dab66
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Base/Interpreter.cpp
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/Base/Interpreter.h
Expand Up @@ -242,6 +242,8 @@ class BaseExport InterpreterSingleton
static const std::string strToPython(const std::string &Str){return strToPython(Str.c_str());}
//@}

PyObject *getValue(const char *key, const char *result_var);

protected:
// singleton
static InterpreterSingleton *_pcSingelton;
Expand Down

0 comments on commit 75dab66

Please sign in to comment.