17 auto global = py::dict(py::module::import(
"__main__").attr(
"__dict__"));
19 m.def(
"test_eval_statements", [global]() {
20 auto local = py::dict();
21 local[
"call_test"] = py::cpp_function([&]() ->
int {
27 "message = 'Hello World!'\n" 40 auto x = local[
"x"].cast<
int>();
45 m.def(
"test_eval", [global]() {
46 auto local = py::dict();
47 local[
"x"] = py::int_(42);
49 return x.cast<
int>() == 42;
52 m.def(
"test_eval_single_statement", []() {
53 auto local = py::dict();
54 local[
"call_test"] = py::cpp_function([&]() ->
int {
58 auto result = py::eval<py::eval_single_statement>(
"x = call_test()", py::dict(), local);
59 auto x = local[
"x"].cast<
int>();
60 return result.is_none() && x == 42;
64 auto local = py::dict();
65 local[
"y"] = py::int_(43);
68 local[
"call_test2"] = py::cpp_function([&](
int value) { val_out =
value; });
71 return val_out == 43 && result.is_none();
74 m.def(
"test_eval_failure", []() {
77 }
catch (py::error_already_set &) {
83 m.def(
"test_eval_file_failure", []() {
86 }
catch (std::exception &) {
object eval_file(str fname, object global=globals(), object local=object())
internal::nested_eval< T, 1 >::type eval(const T &xpr)
void exec(str expr, object global=globals(), object local=object())
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x