Skip to content

Latest commit

 

History

History

Module support

Currently all modules written in C++ are statically linked to libpython.

However, in the long term this will be replaced with a plugin architecture, so that C++ libraries can be directly imported into python and use a symbol table to load Python objects to the runtime PyModule symbol table.

The API to register Python objects in a shared library will be similar to the one provided by pybind/embind/PyTorch/...

DEFINE_MODULE(test, m) { 
    class_<NativeTest>(m, "Test")
        .def("foo", +[](){ std::cout << "Hello, world!\n"; })
        .def("echo", +[](PyObject* obj){ std::cout << obj->to_string() << '\n';})
        .def("test", &Test::test)
        ;
}

and/or

EXPORT_MODULE(MyModule) // where mymodule is a PyModule

and/or

DEFINE_MODULE(test, m) { 
    class_<MyClass>(m, "MyClass") // where MyClass inherits from PyObject
}