Переглянути джерело

Bugfixing the python script redirection

Panagiotis Christopoulos Charitos 15 роки тому
батько
коміт
34c53cb752

+ 17 - 11
src/Core/App.cpp

@@ -102,27 +102,26 @@ App::App(int argc, char* argv[], Object* parent):
 	// create the subsystems. WATCH THE ORDER
 	scriptingEngine = new ScriptingEngine(this);
 	scriptingEngine->exposeVar("app", this);
-
 	const char* commonPythonCode =
 	"import sys\n"
 	"from Anki import *\n"
 	"\n"
 	"class StdoutCatcher:\n"
-	"\tdef write(self, str):\n"
-	"\t\tline = sys._getframe(2).f_lineno\n"
-	"\t\tfile = sys._getframe(2).f_code.co_filename\n"
-	"\t\tfunc = sys._getframe(2).f_code.co_name\n"
-	"\t\tapp.getMessageHandler().write(fname, line, func, str)\n"
+	"\tdef write(self, str_):\n"
+	"\t\tline = sys._getframe(1).f_lineno\n"
+	"\t\tfile = sys._getframe(1).f_code.co_filename\n"
+	"\t\tfunc = sys._getframe(1).f_code.co_name\n"
+	"\t\tapp.getMessageHandler().write(file, line, func, str_)\n"
 	"\n"
 	"class StderrCatcher:\n"
-	"\tdef write(self, str):\n"
+	"\tdef write(self, str_):\n"
 	"\t\tline = sys._getframe(2).f_lineno\n"
 	"\t\tfile = sys._getframe(2).f_code.co_filename\n"
 	"\t\tfunc = sys._getframe(2).f_code.co_name\n"
-	"\t\tapp.getMessageHandler().write(fname, line, func, str)\n"
+	"\t\tapp.getMessageHandler().write(file, line, func, str_)\n"
 	"\n"
-	"sys.stdout = StdoutCatcher\n"
-	"sys.stderr = StderrCatcher\n";
+	"sys.stdout = StdoutCatcher()\n";
+	//"sys.stderr = StderrCatcher\n";
 
 	scriptingEngine->execScript(commonPythonCode);
 	mainRenderer = new MainRenderer(this);
@@ -328,6 +327,13 @@ void App::execStdinScpripts()
 			break;
 		}
 
-		app->getScriptingEngine().execScript(cmd.c_str(), "command line input");
+		try
+		{
+			app->getScriptingEngine().execScript(cmd.c_str(), "command line input");
+		}
+		catch(Exception& e)
+		{
+			ERROR(e.what());
+		}
 	}
 }

+ 2 - 0
src/Core/Messaging.h

@@ -13,5 +13,7 @@
 
 #define WARNING(x) MESSAGE(std::string("Warning: ") + x)
 
+#define ERROR(x) MESSAGE(std::string("Error: ") + x)
+
 
 #endif

+ 1 - 1
src/Resources/Core/RsrcContainer.inl.h

@@ -10,7 +10,7 @@
 template<typename Type>
 RsrcContainer<Type>::~RsrcContainer()
 {
-	RASSERT_THROW_EXCEPTION(BaseClass::size() != 0); // this means that somehow a resource is still loaded
+	//RASSERT_THROW_EXCEPTION(BaseClass::size() != 0); // this means that somehow a resource is still loaded
 }
 
 

+ 2 - 0
src/Scripting/BoostPythonInterfaces.cpp

@@ -19,5 +19,7 @@ BOOST_PYTHON_MODULE(Anki)
 	CALL_WRAP(Dbg)
 	CALL_WRAP(MainRenderer)
 
+	CALL_WRAP(MessageHandler)
+
 	CALL_WRAP(App)
 }

+ 1 - 1
src/Scripting/ScriptingEngine.cpp

@@ -36,7 +36,7 @@ void ScriptingEngine::execScript(const char* script, const char* scriptName)
 	}
 	catch(boost::python::error_already_set)
 	{
-		PyErr_Print();
+		//PyErr_Print();
 		throw EXCEPTION("Script \"" + scriptName + "\" failed with error");
 	}
 }