Пример #1
0
        public Engine()
        {
            var options = new Dictionary <string, object>();

            options["DivisionOptions"] = PythonDivisionOptions.New;
            _history = new NullStream();
            _output  = new EventRaisingStreamWriter(_history);
            _output.StringWritten += _output_StringWritten;
            _engine = Python.CreateEngine(options);
            _engine.Runtime.IO.SetOutput(_history, _output);
            _engine.Runtime.IO.SetErrorOutput(_history, _output);
            _scope = _engine.CreateScope();
            foreach (var t in _pluggable)
            {
                _scope.SetVariable(t.Name, DynamicHelpers.GetPythonTypeFromType(t));
            }
            _scope.SetVariable("CalculatorFunctions", DynamicHelpers.GetPythonTypeFromType(typeof(CalculatorFunctions)));
            _functioncache = new Dictionary <string, string>();
            //hidden functions
            _functioncache.Add("Var", "CalculatorFunctions.Var");
            _functioncache.Add("FncList", "CalculatorFunctions.FncList");
            _functioncache.Add("RegFunction", "CalculatorFunctions.RegFunction");

            foreach (var f in _functions)
            {
                if (_functioncache.ContainsKey(f.Name))
                {
                    continue;
                }
                _functioncache.Add(f.Name, f.FullName);
            }
            LoadBitops();
        }
Пример #2
0
 protected virtual void Dispose(bool native)
 {
     if (_output != null)
     {
         _output.Dispose();
         _output = null;
     }
     if (_history != null)
     {
         _history.Dispose();
         _history = null;
     }
 }