public void CompileAndRun() { GameTypes.D.onDLog += Console.WriteLine; output = new List<string>(); RelayTwo relay = new RelayTwo(); TableTwo programsTable = relay.CreateTable(Program.TABLE_NAME); FunctionDefinition print = new FunctionDefinition("void", "print", new string[] { "string" }, new string[] { "s" }, API_print, FunctionDocumentation.Default()); Program p1 = new Program(); p1.CreateNewRelayEntry(programsTable, "Program"); p1.Init(new ProgramRunner(relay)); p1.sourceCodeContent = "print(42)"; p1.FunctionDefinitions.Add(print); p1.Compile(); Assert.AreEqual(0, p1.GetErrors().Length); for(int i = 0; i < 100; i++) { if(p1.sprakRunner.interpreter != null) { p1.Update(0.1f); } } Assert.AreEqual(1, output.Count); Assert.AreEqual("42", output[0]); }
public void CompileWithError() { RelayTwo relay = new RelayTwo(); TableTwo programsTable = relay.CreateTable(Program.TABLE_NAME); Program p1 = new Program(); p1.CreateNewRelayEntry(programsTable, "Program"); p1.sourceCodeContent = "var x = "; p1.Compile(); Assert.AreEqual(1, p1.GetErrors().Length); }
public Error[] ChangeAndRecompileProgram(string pProgramName, string pNewSourceCodeContent) { Program p = GetProgram(pProgramName); if (p == null) { throw new Exception("Can't find program '" + pProgramName + "' to change and recompile"); } p.sourceCodeContent = pNewSourceCodeContent; Error[] errors = p.Compile(); return(errors); }
public void IncreaseAttempts() { _attempts++; if (_attempts > FAILURE_THRESHOLD) { D.Log("Failures to get through door " + name + " reached " + FAILURE_THRESHOLD + ", will reset code"); _program.sourceCodeContent = _sourceCodeDispenser.GetSourceCode(_program.sourceCodeName).content; _program.Compile(); } else { //D.Log("Attempts for door " + name + " increased to " + _attempts); } }