Skip to content

Commit

Permalink
App: make evalExpression() a class method of DocumentObject
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Sep 23, 2021
1 parent f439e0c commit bfe7a7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/App/DocumentObjectPy.xml
Expand Up @@ -55,7 +55,7 @@
<UserDocu>Register an expression for a property</UserDocu>
</Documentation>
</Methode>
<Methode Name="evalExpression">
<Methode Name="evalExpression" Class="true">
<Documentation>
<UserDocu>Evaluate an expression</UserDocu>
</Documentation>
Expand Down
17 changes: 12 additions & 5 deletions src/App/DocumentObjectPyImp.cpp
Expand Up @@ -346,15 +346,22 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args)
Py_Return;
}

PyObject* DocumentObjectPy::evalExpression(PyObject * args)
PyObject* DocumentObjectPy::evalExpression(PyObject *self, PyObject * args)
{
const char *expr;
if (!PyArg_ParseTuple(args, "s", &expr)) // convert args: Python->C
return NULL; // NULL triggers exception
if (!PyArg_ParseTuple(args, "s", &expr))
return nullptr;

// evalExpression() is a class method and thus 'self' can either be an instance of
// DocumentObjectPy or a type object.
App::DocumentObject* obj = nullptr;
if (self && PyObject_TypeCheck(self, &DocumentObjectPy::Type)) {
obj = static_cast<DocumentObjectPy*>(self)->getDocumentObjectPtr();
}

PY_TRY {
std::shared_ptr<Expression> shared_expr(Expression::parse(getDocumentObjectPtr(), expr));
if(shared_expr)
std::shared_ptr<Expression> shared_expr(Expression::parse(obj, expr));
if (shared_expr)
return Py::new_reference_to(shared_expr->getPyValue());
Py_Return;
} PY_CATCH
Expand Down

0 comments on commit bfe7a7a

Please sign in to comment.