Exemplo n.º 1
0
        public CalculatorEngine()
        {
            TrigonometryMode = TrigonometryMode.DEG;
            ConstantDB       = new ConstantDB();
            _linebuffer      = new StringBuilder();
            _functioncache   = new Dictionary <string, FunctionInformation>();
            _preprocessor    = new Preprocessor(_functioncache, ConstantDB);
            var options = new Dictionary <string, object>();

            options["DivisionOptions"] = PythonDivisionOptions.New;
            _history = new ZeroStream();
            _output  = new EventRedirectedStreamWriter(_history);
            _output.StreamWasWritten += _output_StreamWasWritten;
            _engine = Python.CreateEngine(options);
            _engine.Runtime.IO.SetOutput(_history, _output);
            _engine.Runtime.IO.SetErrorOutput(_history, _output);
            _scope = _engine.CreateScope();

            _functionTypes = new Type[]
            {
                typeof(Trigonometry),
                typeof(Engineering),
                typeof(GeneralFunctions),
                typeof(Variations),
                typeof(TypeFunctions),
                typeof(Statistics)
            };

            FunctionCache.Fill(ref _functioncache, ref _scope, _functionTypes);
        }