/// <summary> /// Run on the statement execution thread. /// </summary> void ExecuteStatements() { lock (scriptText) { textEditor.Write("\r\n"); ScriptSource scriptSource = commandLine.ScriptScope.Engine.CreateScriptSourceFromString(scriptText, SourceCodeKind.Statements); string error = ""; try { executing = true; var errors = new ErrorReporter(); var command = scriptSource.Compile(errors); if (command == null) { // compilation failed error = "Syntax Error: " + string.Join("\nSyntax Error: ", errors.Errors) + "\n"; } else { //GetCommandDispatcher()(() => scriptSource.Execute(commandLine.ScriptScope)); ObjectHandle wrapexception = null; GetCommandDispatcher()(() => scriptSource.ExecuteAndWrap(commandLine.ScriptScope, out wrapexception)); if (wrapexception != null) { error = "Exception : " + wrapexception.Unwrap().ToString() + "\n"; } } } catch (ThreadAbortException tae) { if (tae.ExceptionState is Microsoft.Scripting.KeyboardInterruptException) { Thread.ResetAbort(); } error = "KeyboardInterrupt" + System.Environment.NewLine; } catch (Microsoft.Scripting.SyntaxErrorException exception) { ExceptionOperations eo; eo = commandLine.ScriptScope.Engine.GetService <ExceptionOperations>(); error = eo.FormatException(exception); } catch (Exception exception) { ExceptionOperations eo; eo = commandLine.ScriptScope.Engine.GetService <ExceptionOperations>(); error = eo.FormatException(exception) + System.Environment.NewLine; } executing = false; if (error != "") { textEditor.Write(error); } textEditor.Write(prompt); } }
/// <summary> /// Run on the statement execution thread. /// </summary> void ExecuteStatements() { lock (scriptText) { textEditor.Write("\r\n"); ScriptSource scriptSource = commandLine.ScriptScope.Engine.CreateScriptSourceFromString(scriptText, SourceCodeKind.Statements); string error = ""; try { executing = true; GetCommandDispatcher()(() => scriptSource.Execute(commandLine.ScriptScope)); } catch (ThreadAbortException tae) { if (tae.ExceptionState is Microsoft.Scripting.KeyboardInterruptException) { Thread.ResetAbort(); } error = "KeyboardInterrupt" + System.Environment.NewLine; } catch (Microsoft.Scripting.SyntaxErrorException exception) { ExceptionOperations eo; eo = commandLine.ScriptScope.Engine.GetService <ExceptionOperations>(); error = eo.FormatException(exception); } catch (Exception exception) { ExceptionOperations eo; eo = commandLine.ScriptScope.Engine.GetService <ExceptionOperations>(); error = eo.FormatException(exception) + System.Environment.NewLine; } executing = false; if (error != "") { textEditor.Write(error); } textEditor.Write(prompt); } }