From 5bee287210a2065c6d86cb18ad75cb2a2abff3b3 Mon Sep 17 00:00:00 2001 From: Mansard <nmansard@laas.fr> Date: Fri, 11 Feb 2011 11:00:05 +0100 Subject: [PATCH] Modify the "runFile" function that was not working, at create a new function to call for the shell. --- include/dynamic-graph/python/interpreter.hh | 1 + src/interpreter.cc | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/dynamic-graph/python/interpreter.hh b/include/dynamic-graph/python/interpreter.hh index ce9977b..e19d022 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 23c8b27..ad3e444 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) -- GitLab