Exemple #1
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);
     }
 }
Exemple #2
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);
            }
        }
Exemple #3
0
 public void CompileWith(IPythonEngine engine)
 {
     this.Compiled = engine.Compile(Code, SourceCodeType.Expression);
 }
Exemple #4
0
 public T Evaluate <T>(IPythonByteCode expression, IPythonScope scope = null)
 {
     return((T)Evaluate(expression, scope));
 }