100 lines
3.5 KiB
C#
100 lines
3.5 KiB
C#
using System.Collections;
|
|
using Upsilon.Binder;
|
|
using Upsilon.Evaluator;
|
|
|
|
namespace Upsilon
|
|
{
|
|
public static class Executor
|
|
{
|
|
private static readonly ScriptOptions DefaultOptions = new ScriptOptions();
|
|
|
|
public static Script ParseInput(string input, ScriptOptions options = null)
|
|
{
|
|
if (options == null) options = DefaultOptions;
|
|
var script = new Script(input, "unnamed", options);
|
|
script.Parse();
|
|
return script;
|
|
}
|
|
|
|
public static Script ParseFile(string fileName, ScriptOptions options = null)
|
|
{
|
|
if (options == null) options = DefaultOptions;
|
|
var input = options.ScriptLoader.LoadFile(fileName);
|
|
if (input == null)
|
|
return null;
|
|
var script = new Script(input,fileName, options);
|
|
script.Parse();
|
|
return script;
|
|
}
|
|
|
|
public static Script ParseInputAndEvaluate(string input, ScriptOptions options = null)
|
|
{
|
|
if (options == null) options = DefaultOptions;
|
|
var script = new Script(input, "unnamed", options);
|
|
script.Parse();
|
|
script.Evaluate();
|
|
return script;
|
|
}
|
|
|
|
public static Script ParseFileAndEvaluate(string fileName, ScriptOptions options = null)
|
|
{
|
|
if (options == null) options = DefaultOptions;
|
|
var input = options.ScriptLoader.LoadFile(fileName);
|
|
var script = new Script(input, fileName, options);
|
|
script.Parse();
|
|
script.Evaluate();
|
|
return script;
|
|
}
|
|
|
|
public static Script ContinueWith(Script script, string input, string fileName = "unnamed")
|
|
{
|
|
var s = Script.ContinueWith(script, fileName, input);
|
|
s.Parse();
|
|
return s;
|
|
}
|
|
|
|
|
|
public static Script ContinueWith(Script script, BoundScript bound)
|
|
{
|
|
var s = Script.ContinueWith(script, bound);
|
|
s.Evaluate();
|
|
return s;
|
|
}
|
|
|
|
public static T EvaluateScript<T>(string input, ScriptOptions options = null)
|
|
{
|
|
var script = ParseInput(input, options);
|
|
return script.Evaluate<T>();
|
|
}
|
|
|
|
public static object EvaluateScript(string input, ScriptOptions options = null)
|
|
{
|
|
var script = ParseInput(input, options);
|
|
return script.Evaluate();
|
|
}
|
|
|
|
public static object EvaluateScript(BoundScript input, ScriptOptions options = null)
|
|
{
|
|
var script = new Script(input, options);
|
|
return script.Evaluate();
|
|
}
|
|
|
|
public static T EvaluateFunction<T>(string input, string function, object[] parameters = null, ScriptOptions options = null)
|
|
{
|
|
var script = ParseInputAndEvaluate(input, options);
|
|
return script.EvaluateFunction<T>(function, parameters);
|
|
}
|
|
|
|
public static object EvaluateFunction(string input, string function, object[] parameters = null, ScriptOptions options = null)
|
|
{
|
|
var script = ParseInputAndEvaluate(input, options);
|
|
return script.EvaluateFunction(function, parameters);
|
|
}
|
|
|
|
public static IEnumerator EvaluateFunctionCoroutine(string input, string function, object[] parameters = null, ScriptOptions options = null)
|
|
{
|
|
var script = ParseInputAndEvaluate(input, options);
|
|
return script.EvaluateFunctionCoroutine(function, parameters);
|
|
}
|
|
}
|
|
} |