public static void RunScript(string s) { CompileToMemory ctm = new CompileToMemory(); BooCompiler compiler = new BooCompiler(); compiler.Parameters.Input.Add(new StringInput("BooFile_Module", s)); compiler.Parameters.Pipeline = ctm; compiler.Parameters.Environment = new ClosedEnvironment(ctm); compiler.Parameters.Ducky = true; compiler.Parameters.AddAssembly(typeof(GameModel).Assembly); foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { compiler.Parameters.References.Add(assembly); } CompilerContext context = compiler.Run(); if (context.GeneratedAssembly == null) { foreach (CompilerError error in context.Errors) { MelonLogger.LogError(error.ToString()); } return; } Type[] types = context.GeneratedAssembly.GetTypes(); Type scriptModule = types[types.Length - 1]; MethodInfo mainEntry = scriptModule.Assembly.EntryPoint; mainEntry.Invoke(null, new object[mainEntry.GetParameters().Length]); }
public BooScriptCompiler() { compiler = BooHelpers.CreateBooCompiler(); var parameters = compiler.Parameters; //parameters.Environment = parameters.GenerateInMemory = true; parameters.Ducky = true; parameters.WhiteSpaceAgnostic = false; parameters.References.Clear(); //parameters.LoadDefaultReferences();//do not use! This will cause failures on future calls, within the context of a TShockPlugin(unknown reason). //parameters.StdLib = false; parameters.DisabledWarnings.Add("BCW0016"); //dont warn about unused namespaces... parameters.OutputType = CompilerOutputType.Library; parameters.OutputAssembly = "scripts.dll"; parameters.GenerateCollectible = true; //dont leak assemblies... var pipeline = new CompileToMemory(); //...when we compile them to memory. //parameters.Pipeline = new CompileToFile(); //parameters.Pipeline = new Parse(); injectImportsStep = new InjectImportsStep(); pipeline.Insert(1, injectImportsStep); ensureMethodSignaturesStep = new EnsureMethodSignaturesStep(); pipeline.Insert(2, ensureMethodSignaturesStep); parameters.Pipeline = pipeline; }
/// <summary> /// Override in derived classes to use a different pipeline. /// </summary> protected virtual CompilerPipeline SetUpCompilerPipeline() { CompilerPipeline pipeline = null; if (VerifyGeneratedAssemblies) { pipeline = new CompileToFileAndVerify(); } else { pipeline = new CompileToMemory(); } pipeline.Add(new RunAssembly()); return(pipeline); }