52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace tlang
|
|
{
|
|
public class ApplicationRunner
|
|
{
|
|
public static Stream GetLauncherScript()
|
|
{
|
|
var fileName = System.Environment.GetEnvironmentVariable("TLANG_LAUNCHER_SCRIPT");
|
|
if(!string.IsNullOrWhiteSpace(fileName))
|
|
{
|
|
return File.OpenRead(fileName);
|
|
}
|
|
|
|
return typeof(ApplicationRunner).Assembly.GetManifestResourceStream("tlanglib.launcher.launcher.tlang");
|
|
|
|
}
|
|
public static int Run(List<LexToken> code,string[] args)
|
|
{
|
|
|
|
|
|
|
|
RootEnvironment env=new RootEnvironment();
|
|
|
|
|
|
|
|
Parser parser=new Parser(code);
|
|
parser.LoadEnvironment(env);
|
|
List<TString> args2=new List<TString>();
|
|
foreach(var argument in args)
|
|
{
|
|
args2.Add(new TString(argument));
|
|
}
|
|
|
|
var res= parser.Execute(env,args2.ToArray()) as TNumber;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(res != null)
|
|
{
|
|
return (int)res.Value;
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
}
|
|
} |