public void loadH2Script(string scriptToLoad) { O2Thread.mtaThread(() => { if (scriptToLoad.fileName().starts(this.typeName())) { PublicDI.log.error("We can execute the current type of we will get a recursive load :)"); return; } currentScript = scriptToLoad; statusLabel.set_Text("loading script: {0}".format(scriptToLoad.fileName())); csharpCompiler = new CSharp_FastCompiler(); csharpCompiler.set_OnAstFail(() => { showError("Ast creation failed", csharpCompiler.astErrors()); csharpCompiler_OnAstFail.invoke(); }); csharpCompiler.set_OnAstOK(() => { showInfo("Ast creation Ok"); csharpCompiler_OnAstOk.invoke(); }); csharpCompiler.set_OnCompileFail(() => { showError("Compilation failed", csharpCompiler.compilationErrors()); csharpCompiler_OnCompileFail.invoke(); }); csharpCompiler.set_OnCompileOK(() => { showInfo("Compilation Ok: Executing 1st method"); csharpCompiler_OnCompileOk.invoke(); executeCompiledCode(); }); var sourceCode = ""; PublicDI.CurrentScript = scriptToLoad; csharpCompiler.CompilerOptions.SourceCodeFile = scriptToLoad; if (scriptToLoad.extension(".h2")) { sourceCode = H2.load(scriptToLoad).SourceCode; } if (scriptToLoad.extension(".o2") || scriptToLoad.extension(".cs")) { sourceCode = scriptToLoad.contents(); } if (sourceCode.valid()) { csharpCompiler.compileSnippet(sourceCode); } else { statusLabel.set_Text("Non supported file").textColor(this, Color.Red); } }); }
public static Assembly compile(this string pathToFileToCompile, bool generateDebugSymbols) { PublicDI.CurrentScript = pathToFileToCompile; var csharpCompiler = new CSharp_FastCompiler().generateDebugSymbols(generateDebugSymbols); var compileProcess = new AutoResetEvent(false); csharpCompiler.set_OnCompileFail(() => compileProcess.Set()); csharpCompiler.set_OnCompileOK(() => compileProcess.Set()); O2Thread.mtaThread(() => csharpCompiler.compileSourceCode(pathToFileToCompile.contents())); compileProcess.WaitOne(); return(csharpCompiler.assembly()); }
public static Assembly compile_CodeSnippet(this string codeSnipptet, bool generateDebugSymbols) { //Note we can't use the precompiled engines here since there is an issue of the resolution of this code dependencies var csharpCompiler = new CSharp_FastCompiler().debugMode(true) .generateDebugSymbols(generateDebugSymbols); var compileProcess = new AutoResetEvent(false); csharpCompiler.set_OnAstFail(() => compileProcess.Set()); csharpCompiler.set_OnCompileFail(() => compileProcess.Set()); csharpCompiler.set_OnCompileOK(() => compileProcess.Set()); csharpCompiler.compileSnippet(codeSnipptet); compileProcess.WaitOne(); var assembly = csharpCompiler.assembly(); return(assembly); }