Open grayj2 opened 4 days ago
Binding smart pointers with pydind11 is complex.
Concerning the stubs, your solution was a step in the right direction. I fixed it inside cpp_to_python, by applying the changes to unique_ptr and shared_ptr before vector:
Now, concerning your usage:
For an example, see this integration test:
https://github.com/pthom/litgen/blob/main/src/litgen/integration_tests/mylib/smart_ptr.h
And its bindings:
https://github.com/pthom/litgen/blob/main/src/litgen/integration_tests/mylib/smart_ptr.h.pyi
Where I had to specify the holder type for SmartElem
Read here the doc for class_held_as_shared__regex:
Note: you will need to update litgen to the latest commit
Thank you for the updates! This did the trick.
Understood about the caveats on smart pointers. Mainly just tinkering at this point to understand how to use litgen. So far it seems pretty straight forward.
Starting to use litgen to make bindings and ran into an issue when using vectors of smart points. litgen does not seem to interpret vectors of smart pointers correctly.
example.h
resulting stubs with no options specified which are obviously wrong and do not throw any errors when generating other than black formatting errors.
I was able to get around this and get something more expected using the following type replacement option and regex
This results in stubs looking like this
Im not sure if this is best approach or just the naive solution. Considering how smart pointers of a class and a vector of classes gets bound, I would expect to get this result. Would appreciate your insight.