Add py::exec() as a shortcut for py::eval<py::eval_statements>()

This commit is contained in:
Dean Moldovan
2017-04-30 01:53:06 +02:00
parent 0c4e0372a3
commit 076c738641
3 changed files with 25 additions and 12 deletions

View File

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