Support raw string literals as input for py::eval (#766)

* Support raw string literals as input for py::eval
* Dedent only when needed
This commit is contained in:
Dean Moldovan
2017-03-29 00:27:56 +02:00
committed by Wenzel Jakob
parent 6db60cd945
commit 194d8b99b3
3 changed files with 36 additions and 5 deletions

View File

@@ -20,11 +20,21 @@ test_initializer eval([](py::module &m) {
return 42;
});
auto result = py::eval<py::eval_statements>(
"print('Hello World!');\n"
"x = call_test();",
// Regular string literal
py::eval<py::eval_statements>(
"message = 'Hello World!'\n"
"x = call_test()",
global, local
);
// Multi-line raw string literal
auto result = py::eval<py::eval_statements>(R"(
if x == 42:
print(message)
else:
raise RuntimeError
)", global, local
);
auto x = local["x"].cast<int>();
return result == py::none() && x == 42;