/// <summary> /// Метод добавления логгера /// </summary> /// <param name="logger"></param> public static void AddLogger(ILogger logger) { _printFunction += logger.Print; _printArgsFunction += logger.Print; _errorPrintFunction += logger.ErrorPrint; _errorPrintArgsFunction += logger.ErrorPrint; }
/// <summary> /// Метод удаление логгера /// </summary> /// <param name="logger"></param> public static void RemoveLogger(ILogger logger) { _printFunction -= logger.Print; _printArgsFunction -= logger.Print; _errorPrintFunction -= logger.ErrorPrint; _errorPrintArgsFunction -= logger.ErrorPrint; }
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()); }
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)}"); } }
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); }
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); }
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); }
public void Start(PrintFunction printFunction) { for (int i = 1; i <= 60; i++) { if (i % 10 == 0) { if (printFunction != null) { printFunction.Invoke(i); } } } }
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()); }
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); } }
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); } }
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 ); } }
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); }
/// <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); }
public void Print(PrintFunction printFunction) { printFunction(this.ToString()); }