tlang-interperter-cs/tlanglib/Program.cs

52 lines
1.2 KiB
C#
Raw Normal View History

2023-03-10 10:12:36 +00:00
using System.Collections.Generic;
using System.IO;
namespace tlang
2023-03-10 04:33:58 +00:00
{
public class ApplicationRunner
{
public static Stream GetLauncherScript()
{
var fileName = System.Environment.GetEnvironmentVariable("TLANG_LAUNCHER_SCRIPT");
if(!string.IsNullOrWhiteSpace(fileName))
{
return File.OpenRead(fileName);
}
2023-03-10 10:12:36 +00:00
2023-03-10 04:33:58 +00:00
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;
}
}
}