예제 #1
0
        /// <summary>
        /// Метод добавления логгера
        /// </summary>
        /// <param name="logger"></param>
        public static void AddLogger(ILogger logger)
        {
            _printFunction     += logger.Print;
            _printArgsFunction += logger.Print;

            _errorPrintFunction     += logger.ErrorPrint;
            _errorPrintArgsFunction += logger.ErrorPrint;
        }
예제 #2
0
        /// <summary>
        /// Метод удаление логгера
        /// </summary>
        /// <param name="logger"></param>
        public static void RemoveLogger(ILogger logger)
        {
            _printFunction     -= logger.Print;
            _printArgsFunction -= logger.Print;

            _errorPrintFunction     -= logger.ErrorPrint;
            _errorPrintArgsFunction -= logger.ErrorPrint;
        }
예제 #3
0
        public void PrintTwoIntegers()
        {
            StringWriter  writer   = new StringWriter();
            PrintFunction function = new PrintFunction(writer);

            Assert.IsNull(function.Apply(null, null, new object[] { 123, 456 }));

            Assert.AreEqual("123456", writer.ToString());
        }
예제 #4
0
        static void Main(string[] args)
        {
            var interpreter = new Interpreter();

            interpreter.RunProgram(Parser.Parse(SourceFile.Read(args[0])));
            foreach (var variable in interpreter.Constants.OrderBy(x => x.Key, StringComparer.Ordinal))
            {
                Console.WriteLine($" - {variable.Key}: {PrintFunction.ValueToString(variable.Value)}");
            }
        }
예제 #5
0
        public void AddRecord(RecordType type, char[,] map, PrintFunction print)
        {
            Record record = new Record();

            record.Type = type;
            record.Map  = map;

            record.Turn = Simulation.Time.Turn;
            record.Year = Simulation.Time.Shuffle;

            record.printFunction = print;
            Records.Add(record);
        }
예제 #6
0
        public void AddRecord(RecordType type, War war, PrintFunction print)
        {
            Record record = new Record();

            record.Type = type;
            record.War  = war;

            record.Turn = Simulation.Time.Turn;
            record.Year = war.Begin;

            record.printFunction = print;
            Records.Add(record);
        }
예제 #7
0
        public void AddRecord(TerrainFeatures terrain, PrintFunction print)
        {
            Record record = new Record();

            record.Type    = RecordType.CreateTerrainFeature;
            record.Terrain = terrain;

            record.Turn = Simulation.Time.Turn;
            record.Year = Simulation.Time.Shuffle;

            record.printFunction = print;
            Records.Add(record);
        }
예제 #8
0
 public void Start(PrintFunction printFunction)
 {
     for (int i = 1; i <= 60; i++)
     {
         if (i % 10 == 0)
         {
             if (printFunction != null)
             {
                 printFunction.Invoke(i);
             }
         }
     }
 }
예제 #9
0
        public void EvaluatePrintFunction()
        {
            Machine      machine = new Machine();
            var          print   = new PrintFunction(machine);
            StringWriter writer  = new StringWriter();

            machine.Output = writer;

            var result = print.Apply(machine.Environment, new object[] { "bar" }, null);

            Assert.IsNull(result);
            Assert.AreEqual("bar\r\n", writer.ToString());
        }
예제 #10
0
        protected void AssertOutput(Lua lua, string function, string expectedOutput, string message)
        {
            expectedOutput = expectedOutput.Replace("\r\n", "\n");               // Get rid of Windows problems.
            using (StringWriter writer = new StringWriter( ))
            {
                PrintFunction func = new PrintFunction(writer);
                lua["print"]  = func;
                lua["remote"] = RemoteFunction.Instance;

                ((LuaFunction)lua[function]).Call();

                Assert.AreEqual(expectedOutput, writer.ToString( ).Trim( ), message);
            }
        }
예제 #11
0
 static void printAst(ParseTree output, PrintFunction print)
 {
     if (output.Status == ParseTreeStatus.Error)
     {
         foreach (var msg in output.ParserMessages)
         {
             Console.WriteLine(msg);
         }
     }
     else
     {
         print(output.Root, 0);
     }
 }
예제 #12
0
        protected void AssertOutput( Lua lua, string function, string expectedOutput, string message )
        {
            expectedOutput = expectedOutput.Replace( "\r\n", "\n" ); // Get rid of Windows problems.
            using( StringWriter writer = new StringWriter( ) )
            {
                PrintFunction func = new PrintFunction( writer );
                lua["print"] = func;
                lua["remote"] = RemoteFunction.Instance;

                ((LuaFunction)lua[function]).Call();

                Assert.AreEqual( expectedOutput, writer.ToString( ).Trim( ), message );
            }
        }
예제 #13
0
        static void Main(string[] args)
        {
            int          x = 16, y = 2;
            MathFunction mf = MathTool.sum;

            Console.WriteLine("mf({0}, {1}) = {2}", x, y, mf(x, y));
            mf = MathTool.diff;
            Console.WriteLine("mf({0}, {1}) = {2}", x, y, mf(x, y));
            PrintFunction pf = MathTool.printSquare;

            pf += MathTool.printSquareRoot;
            pf(x);
            pf -= MathTool.printSquare;
            Console.WriteLine();
            pf(y);
            Func <int, int, int> func = MathTool.sum;

            Console.WriteLine("func({0}, {1}) = {2}", x, y, func(x, y));
            Action <int> action = MathTool.printSquare;

            action(x);
        }
예제 #14
0
파일: Sq.Managed.cs 프로젝트: bartwe/SqNET
 /// <summary>Sets the print function of the virtual machine. This function is used by the built-in function '::print()' to output text.</summary>
 public void SetPrintFunc(PrintFunction print, PrintFunction error)
 {
     _printHook = (IntPtr v, string message) => print(this, message);
     _errorHook = (IntPtr v, string message) => error(this, message);
     Unmanaged.SetPrintFunc(Pointer, _printHook, _errorHook);
 }
예제 #15
0
파일: Set.cs 프로젝트: kovila77/Sets
 public void Print(PrintFunction printFunction)
 {
     printFunction(this.ToString());
 }