Ejemplo n.º 1
0
 public void ExecutePythonCode(string code)
 {
     pySource = pyEngine.CreateScriptSourceFromString(code,SourceCodeKind.InteractiveCode);
     object output = pySource.Execute(pyScope);
     if (output != null) Console.Echo(pyEngine.Operations.Format(output));
     ShowResults();
 }
Ejemplo n.º 2
0
        public ReplayReader()
        {
            // Lib should be in SearchPath, but we need to add our own python files as well
            ICollection<string> paths = m_engine.GetSearchPaths();
            paths.Add(m_blizzScriptPath);
            m_engine.SetSearchPaths(paths);

            // create global scope, we only need 1 of those
            m_scope = m_engine.CreateScope();

            // load our API file we're going to communicate with
            m_source = m_engine.CreateScriptSourceFromFile(m_blizzScriptPath + m_replayLibPyFile);
            m_source.Execute(m_scope);
        }
Ejemplo n.º 3
0
        private void Compile()
        {
            try
            {
                _source = _engine.CreateScriptSourceFromString("import clr" + Environment.NewLine + "clr.AddReference('mtrand')" + Environment.NewLine);
                _source.Execute(_scope);
                _source = _engine.CreateScriptSourceFromString(textBox_CodeIn.Text);

                dynamic res2 = _source.Execute(_scope);
                if (res2 != null)
                    textBox_CodeOut.Text += Environment.NewLine + ">>> " + _builtin.str(res2);
                textBox_CodeOut.SelectionStart = textBox_CodeOut.TextLength;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Error compile");
            }
            toolStripStatusLabel.Text = "Compile done";
        }
Ejemplo n.º 4
0
        protected override int RunFile(ScriptSource source)
        {
            if (this.ScriptScope == null)
            {
                this.ScriptScope = this.Engine.CreateScope();

                this.ScriptScope.SetVariable(
                    "time",
                    AFunc.Create(
                        "time",
                        (Func<Aplus, AType>)Time,
                        1,
                        "returns the user time of the current process"
                    )
                );
            }

            try
            {
                AType result = source.Execute<AType>(this.ScriptScope);
                Console.WriteLine(result.ToString(), Style.Out);
            }
            catch (Error error)
            {
                Console.ErrorOutput.Write(error);
                return 1;
            }
            catch (Exception)
            {

                throw;
            }
            return 0;
        }
Ejemplo n.º 5
0
 protected void LoadFile(ScriptSource source)
 {
     AType result;
     try
     {
         result = source.Execute<AType>(this.ScriptScope);
     }
     catch (Exception e)
     {
         UnhandledException(e);
     }
 }
Ejemplo n.º 6
0
 private int GetResult(ScriptEngine engine, ScriptSource source) {
     var scope = engine.CreateScope();
     return engine.Operations.ConvertTo<int>(source.Execute(scope) ?? 0);
 }