Skip to content
Snippets Groups Projects
Commit 7923cd32 authored by graeser's avatar graeser Committed by graeser@PCPOOL.MI.FU-BERLIN.DE
Browse files

You call now also construct functions from multiline python function bodies.

[[Imported from SVN: r2386]]
parent ce127cec
No related branches found
No related tags found
No related merge requests found
......@@ -184,13 +184,19 @@ class PythonFunction :
/**
* \brief Create PythonFunction from string expression.
*
* This creates a python function with the given name.
* This creates a python function with the given name. If expression contains no newline
* it is directly evaluated and returned. If it contains a newline it is used as function
* body and expected to call return itself.
*/
PythonFunction(const std::string name, const std::string expression)
{
// create a python function
std::stringstream s;
s << "def " << name << "(x,i=0):\n return " << expression;
std::string::size_type newline = expression.find("\n");
if (newline != std::string::npos)
s << "def " << name << "(x,i=0):\n" << expression;
else
s << "def " << name << "(x,i=0):\n return " << expression;
PyRun_SimpleString(s.str().c_str());
// get reference for python function
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment