Repository navigation
Replies: 5 comments
|
To answer my own question, I think #1071 is probably most of the answer to the first question. (Just writing down the question and what possible directions seem to have helped here) |
|
Answering my own question again - the answer to the second question maybe as simple as setting |
|
There is more to the first question: needs implicit conversion between py::list and std::vector too |
|
The answer to the 2nd question seems to be adding a |
|
I think the 2nd question is not solvable for two reasons: (1) pybind11 / python does not let you overload the "assign" method, (2) original c++ code overloads the "operator=". |
Uh oh!
There was an error while loading. Please reload this page.
I feel like the first of my question is something to do with doing a custom class of std::vector, so I need to understand stl_bind.h better, and the 2nd is possibly related to trying to implement a dictionary-like class, but here it goes:
Question 1: the c++ method I like to bind is like this:
MyclassA children[] = {instanceA_1, instanceA_2};
InstanceB.methodC(children, 2)
I.e. methodC's signature is (MyClassA[], count), an array of instances of MyClassA.
InstanceA_1 and InstanceA_2 are separate constructed instances of MyClassA.
In the python code, I feel like I should have an array of these, or something (a custom container based on std::vector) that behaves like a python array that I can make, and have the std::vector converted to MyClass[] as it passed from python to c++?
How do I go about this?
Question 2: dictionary-like rvalues.
The c++ code is used like this:
InstanceA.methodB("stringC") = valueD;
Where internals of instanceA is modified with an overloaded "=" operator, based on input "stringC". Without the "stringC" argument, I feel like this should be a def_property or a def_readwrite, but with "stringC" it really looks like assigning to a dictionary key-value pair or trying to implement a custom object that looks and behaves like a dictionary.
How do I go about binding such a method?
Sorry if either are answered in the docs... I think the first question maybe related to the custom type with std::vector section, but I don't understand it... (I.e. maybe the documentation needs extending). The 2nd question is probably a composite of different section involving references types, etc.... again if it is answered, perhaps the answer could be expanded or more explicit.
All reactions