5 m.def(
"add", [](
int i,
int j) {
return i +
j; });
8 int main(
int argc,
char *argv[]) {
10 throw std::runtime_error(
"Expected test.py file as the first argument");
11 auto test_py_file = argv[1];
13 py::scoped_interpreter guard{};
15 auto m = py::module::import(
"test_cmake_build");
16 if (
m.attr(
"add")(1, 2).cast<int>() != 3)
17 throw std::runtime_error(
"embed.cpp failed");
19 py::module::import(
"sys").attr(
"argv") =
py::make_tuple(
"test.py",
"embed.cpp");
PYBIND11_EMBEDDED_MODULE(test_cmake_build, m)
object eval_file(str fname, object global=globals(), object local=object())
int main(int argc, char *argv[])
Tuple< Args... > make_tuple(Args...args)
Creates a tuple object, deducing the target type from the types of arguments.