Init() public method

public Init ( GameWorld2.ProgramRunner pProgramRunner ) : void
pProgramRunner GameWorld2.ProgramRunner
return void
Beispiel #1
0
        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 Program CreateProgram(string pName, string pSourceCodeContent, string pNameOfSourceCode)
        {
            Program newProgram = new Program();
            newProgram.CreateNewRelayEntry(_programTable, typeof(Program).Name);
            newProgram.name = pName;
            newProgram.sourceCodeContent = pSourceCodeContent;
            newProgram.sourceCodeName = pNameOfSourceCode;
            newProgram.Init(this);

            _newPrograms.Add(newProgram);

            return newProgram;
        }