Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include<iostream>
- #include"pybind11pybind11.h"
- namespace py = pybind11;
- class Test
- {
- public:
- Test(const std::string &s);
- ~Test();
- void printStr();
- private:
- std::string _s;
- };
- #include "Test.h"
- PYBIND11_MODULE(TestModule, m)
- {
- py::class_<Test>(m, "Test")
- .def(py::init<const std::string &>())
- .def("printStr", &Test::printStr);
- }
- Test::Test(const std::string &s) : _s(s)
- {
- }
- Test::~Test()
- {
- }
- void Test::printStr()
- {
- std::cout << "---> " << _s << std::endl;
- }
- #include"Test.h"
- int main(int argc, char **argv)
- {
- PyImport_AppendInittab("TestModule", PyInit_TestModule);
- Py_Initialize();
- PyRun_SimpleString("import TestModule");
- PyRun_SimpleString("t = TestModule.Test("str")");
- PyRun_SimpleString("t.printStr()");
- Py_Finalize();
- getchar();
- return 1;
- }
Add Comment
Please, Sign In to add comment