Example #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);
        }
Example #2
0
 public void Dispose()
 {
     if (_output != null)
     {
         _output.Dispose();
         _output = null;
     }
     if (_history != null)
     {
         _history.Dispose();
         _history = null;
     }
 }