-
Notifications
You must be signed in to change notification settings - Fork 120
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Feature Description
Hi waf. I've been trying to incorporate CSharpRepl into my Godot game. I tweak the source code to overcome some of the technical problems with Godot. I wonder if some of them can be implemented in the official repo.
My architecture is to run a http server within the Godot game, in which CSharpRepl is used to only run the code.
Then I use a CSharpRepl console as a client sending actual code to the Godot game to execute. They have the same references and imports.
Here are some tweaks I made to make it work.
- Godot API calls are wrappers around actual C++ functions. We should reference additional assemblies in
ScriptRunner.CreateSuccessfulResult, and add dependencies toScriptRunner.assemblyLoader, as talked about here. - We can only run some non-thread-safe Godot API in the main thread. Thus, we need a configurable
ConfigureAwait(true/false)behaviour, especially for executing the actual piece of code. - There will be no arguments returned by
Environment.GetCommandLineArgs(), and accessingRootCommand.ExecutablePathcauses exception. We need a customizableRootCommand. - Add a event handler to customize code evaluation in
ReadEvalPrintLoop, and a command line configuration to prevent the client from executing the code. - Make some classes and methods
publicinCSharpRepl.csproj
Here is the example piece for (4).
// Add a event handler
public event Func<string, Task<EvaluationResult>>? EvaluatingInput;
if (config.RunRoslyn)
{
result = await roslyn
.EvaluateAsync(response.Text, config.LoadScriptArgs, response.CancellationToken)
.ConfigureAwait(true);
}
else if (EvaluatingInput != null)
{
result = await EvaluatingInput.Invoke(response.Text);
}
else
{
console.WriteErrorLine(
$"[Eval] if {nameof(Configuration.RunRoslyn)} is false, please provide a runner via{nameof(EvaluatingInput)}");
result = new EvaluationResult.Cancelled();
}Looking forward to hear some suggestions.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request