Skip to content
Discussion options

You must be logged in to vote

You are better of using std::function since it is natively supported by pybind11.
Also you will need to expose data_s to python via pybind11 else you will not be able to access elements

with small change i have below working example , i have added inline comments as well. Also,I have just clubbed to one cpp file for simplicity

#include <pybind11/pybind11.h>

namespace py = pybind11;

#include <pybind11/functional.h>
// a struct
struct data_s {
    unsigned int sequence_counter;
    unsigned int byte_count;
    unsigned char array[100];
};

Python
// class with a constructor and one method/function
class My_class {
public:
    My_class(std::function<void *(const struct data_s &)> data_hand…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by TrondMelen
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants