App: add DocumentObjectPy.evalExpression()

Allow easy evlauation of expression.
This commit is contained in:
Zheng, Lei
2019-09-30 13:41:01 +08:00
committed by wmayer
parent d68de72578
commit 4bf4444d81
2 changed files with 19 additions and 0 deletions

View File

@@ -368,6 +368,20 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args)
Py_Return;
}
PyObject* DocumentObjectPy::evalExpression(PyObject * args)
{
const char *expr;
if (!PyArg_ParseTuple(args, "s", &expr)) // convert args: Python->C
return NULL; // NULL triggers exception
PY_TRY {
boost::shared_ptr<Expression> shared_expr(Expression::parse(getDocumentObjectPtr(), expr));
if(shared_expr)
return Py::new_reference_to(shared_expr->getPyValue());
Py_Return;
} PY_CATCH
}
PyObject* DocumentObjectPy::recompute(PyObject *args)
{
PyObject *recursive=Py_False;