diff --git a/include/dynamic-graph/python/interpreter.hh b/include/dynamic-graph/python/interpreter.hh index ce9977bbd193a0f1856ad58406971701e67435d7..e19d0220356eb84d4ec8da9a9b7871a2c75c0526 100644 --- a/include/dynamic-graph/python/interpreter.hh +++ b/include/dynamic-graph/python/interpreter.hh @@ -44,6 +44,7 @@ namespace dynamicgraph { /// \brief Method to exectue a python script. /// \param filename the filename void runPythonFile( std::string filename ); + void runMain( void ); /// \brief Process input stream to send relevant blocks to python /// \param stream input stream diff --git a/src/interpreter.cc b/src/interpreter.cc index 23c8b270e4a49d5fc529cdd09b49f6b1ce0ee3db..ad3e44408ea7f590e2c2a29109ca154737c94c0c 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -100,13 +100,20 @@ std::string Interpreter::python( const std::string& command ) void Interpreter::runPythonFile( std::string filename ) { - Py_Finalize(); - Py_Initialize(); - PyRun_SimpleString(pythonPrefix[0].c_str()); - PyRun_SimpleString(pythonPrefix[1].c_str()); - PyRun_SimpleString(pythonPrefix[2].c_str()); - PyRun_SimpleString(pythonPrefix[4].c_str()); - PyRun_SimpleFile(NULL, filename.c_str()); + PyObject* pymainContext = globals_; + PyRun_File(fopen( filename.c_str(),"r" ), filename.c_str(), + Py_file_input, pymainContext,pymainContext); + if (PyErr_Occurred()) + { + std::cout << "Error occures..." << std::endl; + PyErr_Print(); + } +} + +void Interpreter::runMain( void ) +{ + const char * argv [] = { "dg-embedded-pysh" }; + Py_Main(1,const_cast<char**>(argv)); } std::string Interpreter::processStream(std::istream& stream, std::ostream& os)