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