diff options
Diffstat (limited to '3rdparty')
| -rw-r--r-- | 3rdparty/python-console/modified/pyinterpreter.cc | 22 | ||||
| -rw-r--r-- | 3rdparty/python-console/modified/pyinterpreter.h | 1 | 
2 files changed, 23 insertions, 0 deletions
| diff --git a/3rdparty/python-console/modified/pyinterpreter.cc b/3rdparty/python-console/modified/pyinterpreter.cc index f53207ad..89c9b88c 100644 --- a/3rdparty/python-console/modified/pyinterpreter.cc +++ b/3rdparty/python-console/modified/pyinterpreter.cc @@ -153,3 +153,25 @@ void pyinterpreter_release()  {      PyEval_ReleaseThread(m_threadState);  } + +std::string pyinterpreter_execute_file(const char *python_file, int *errorCode) +{ +    PyEval_AcquireThread(m_threadState); +    *errorCode = 0; +    std::string res; +    FILE *fp = fopen(python_file, "r"); +    if (fp == NULL) { +        *errorCode = 1; +        res = "Fatal error: file not found " + std::string(python_file) + "\n"; +        return res; +    } + +    if (PyRun_SimpleFile(fp, python_file)==-1) { +        *errorCode = 1; +        PyErr_Print(); +    } +    res = redirector_take_output(m_threadState); + +    PyEval_ReleaseThread(m_threadState); +    return res; +} diff --git a/3rdparty/python-console/modified/pyinterpreter.h b/3rdparty/python-console/modified/pyinterpreter.h index 1a85c1fb..48512507 100644 --- a/3rdparty/python-console/modified/pyinterpreter.h +++ b/3rdparty/python-console/modified/pyinterpreter.h @@ -33,4 +33,5 @@ void pyinterpreter_initialize();  void pyinterpreter_finalize();  void pyinterpreter_aquire();  void pyinterpreter_release(); +std::string pyinterpreter_execute_file(const char *python_file, int *errorCode);  #endif // PYINTERPRETER_H | 
