Ejemplo n.º 1
0
        /// <summary>
        /// Same as <see cref="Execute{T}(IPythonScope)"/>, but uses RTTI
        /// </summary>
        /// <param name="pythonScope"></param>
        /// <returns></returns>
        public dynamic Execute(IPythonScope pythonScope)
        {
            pythonScope = pythonScope ?? PythonEngine.Instance.DefaultScope;
            ScriptScope scope = ((PythonScope)pythonScope).Scope;

            return(_code.Execute(scope));
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Evaluate an expression, and return the result
 /// </summary>
 /// <param name="expression">Expression to evaluate</param>
 /// <param name="scope">(Optional) the scope to evaluate the action in</param>
 /// <exception cref="PythonException"></exception>
 /// <returns>The result of the expression</returns>
 /// <seealso cref="Evaluate{T}(string,IPythonScope)"/>
 public dynamic Evaluate(String expression, IPythonScope scope = null)
 {
     try
     {
         IPythonByteCode compiled = Compile(expression, SourceCodeKind.Expression);
         return(Evaluate(compiled, scope));
     }
     catch (PythonException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new PythonException(e);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Evaluate the compiled expression
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="scope"></param>
        /// <returns></returns>
        /// <seealso cref="Evaluate{T}(IPythonByteCode,IPythonScope)"/>
        public dynamic Evaluate(IPythonByteCode expression, IPythonScope scope = null)
        {
            ScriptScope myscope = scope != null ? ((PythonScope)scope).Scope : this._pyScope;

            try
            {
                return(((PythonByteCode)expression).Execute(myscope));
            }
            catch (PythonException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new PythonException(e);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Execute python code
        /// </summary>
        /// <param name="code">The code to execute</param>
        /// <param name="scope">(optional)</param>
        /// <exception cref="PythonException"></exception>
        public void Execute(String code, IPythonScope scope = null)
        {
            ScriptScope myscope = scope != null ? ((PythonScope)scope).Scope : this._pyScope;

            Execute(code, myscope);
        }
Ejemplo n.º 5
0
 public T Evaluate <T>(IPythonByteCode expression, IPythonScope scope = null)
 {
     return((T)Evaluate(expression, scope));
 }
Ejemplo n.º 6
0
 /// <summary>
 ///     Evaluate an expression, and return the result
 /// </summary>
 /// <typeparam name="T">The (C#) Type to coerce the value of the expression to</typeparam>
 /// <param name="expression">
 /// Expression to evaluate
 /// </param>
 /// <param name="scope">(Optional) the scope to evaluate the action in</param>
 /// <exception cref="PythonException"></exception>
 /// <returns>The result of the expression, coerced to type T</returns>
 public T Evaluate <T>(String expression, IPythonScope scope = null)
 {
     return((T)Evaluate(expression, scope));
 }