Skip to content

Commit

Permalink
Merge pull request scriptcs#235 from glennblock/232
Browse files Browse the repository at this point in the history
Adding dumping return values in the REPL scriptcs#232
  • Loading branch information
filipw committed May 12, 2013
2 parents 74a839d + bada79e commit 8ea6fe1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/ScriptCs.Core/IScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace ScriptCs
public interface IScriptEngine
{
string BaseDirectory { get; set; }
void Execute(string code, IEnumerable<string> references, IEnumerable<string> namespaces, ScriptPackSession scriptPackSession);
object Execute(string code, IEnumerable<string> references, IEnumerable<string> namespaces, ScriptPackSession scriptPackSession);
}
}
5 changes: 3 additions & 2 deletions src/ScriptCs.Engine.Roslyn/RoslynScriptDebuggerEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public RoslynScriptDebuggerEngine(IScriptHostFactory scriptHostFactory, ILog log
this._logger = logger;
}

protected override void Execute(string code, Session session)
protected override object Execute(string code, Session session)
{
_logger.Debug("Compiling submission");
var submission = session.CompileSubmission<object>(code);
Expand Down Expand Up @@ -59,7 +59,7 @@ protected override void Execute(string code, Session session)
try
{
_logger.Debug("Invoking method.");
method.Invoke(null, new[] { session });
return method.Invoke(null, new[] { session });
}
catch (Exception e)
{
Expand All @@ -73,6 +73,7 @@ protected override void Execute(string code, Session session)
throw new ScriptExecutionException(message);
}
}
return null;
}
}
}
9 changes: 5 additions & 4 deletions src/ScriptCs.Engine.Roslyn/RoslynScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public string BaseDirectory
set { _scriptEngine.BaseDirectory = value; }
}

public void Execute(string code, IEnumerable<string> references, IEnumerable<string> namespaces, ScriptPackSession scriptPackSession)
public object Execute(string code, IEnumerable<string> references, IEnumerable<string> namespaces, ScriptPackSession scriptPackSession)
{
_logger.Info("Starting to create execution components");
_logger.Debug("Creating script host");
Expand Down Expand Up @@ -61,13 +61,14 @@ public void Execute(string code, IEnumerable<string> references, IEnumerable<str
}

_logger.Info("Starting execution");
Execute(code, session);
var result = Execute(code, session);
_logger.Info("Finished execution");
return result;
}

protected virtual void Execute(string code, Session session)
protected virtual object Execute(string code, Session session)
{
session.Execute(code);
return session.Execute(code);
}
}
}
10 changes: 9 additions & 1 deletion src/ScriptCs/Repl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using Common.Logging;
using ScriptCs.Contracts;
using ServiceStack.Text;

namespace ScriptCs
{
Expand Down Expand Up @@ -57,7 +58,14 @@ public void Execute(string script)
try
{
Console.ForegroundColor = ConsoleColor.Cyan;
ScriptEngine.Execute(script, References, DefaultNamespaces, ScriptPackSession);
var result = ScriptEngine.Execute(script, References, DefaultNamespaces, ScriptPackSession);
if (result != null)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(result.ToJsv()

);
}
}
catch (Exception ex)
{
Expand Down
3 changes: 3 additions & 0 deletions src/ScriptCs/ScriptCs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\PowerArgs.1.5.0.0\lib\net40\PowerArgs.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Text">
<HintPath>..\..\packages\ServiceStack.Text.3.9.44\lib\net35\ServiceStack.Text.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
Expand Down
1 change: 1 addition & 0 deletions src/ScriptCs/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<package id="Common.Logging.Log4Net" version="2.0.1" targetFramework="net45" />
<package id="log4net" version="1.2.10" targetFramework="net45" />
<package id="PowerArgs" version="1.5.0.0" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.44" targetFramework="net45" />
</packages>
3 changes: 2 additions & 1 deletion test/ScriptCs.Engine.Roslyn.Tests/RoslynScriptEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public TestRoslynScriptEngine(IScriptHostFactory scriptHostFactory, ILog logger)

public Session Session { get; set; }

protected override void Execute(string code, Session session)
protected override object Execute(string code, Session session)
{
Session = session;
return null;
}
}

Expand Down

0 comments on commit 8ea6fe1

Please sign in to comment.