Replies: 1 comment
-
Ok, I think the error is due to that ssmap is bind in dt module, then in vp module, the type (ssmap) is used as an input. So the question is if I can only put the binding of ssmap in a different module, is there a solution (binding side)? Looking for suggestions. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Data type:
std::map<std::String, std::String> ssmap;
binding code:
dt.cpp (-> import dt)
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include "./ssmap.h"
PYBIND11_MAKE_OPAQUE(std::map<std::String, std::String>>)
void bind_string(py::module &m)
{
py::classstd::String pyClass(m, "String);
pyClass.def(py::init<const std::String&>(), py::return_value_policy::move);
...
}
void bind_ssmap(py::module &m)
{
py::bind_map<std::String, std::String>>(m, "ssmap");
}
...
Then in another module, I'll use ssmap:
vp.cpp (import vp)
void bind_vp(py::module &m)
{
py::class pyClass(m, "vp", py::module_local());
pyClass.def("reset", &vp::reset, py::arg("val")); ---> val is type of ssmap
}
// test script:
import dt
import vp
val = dt.ssmap()
print("type of val is ", type(val))
str = dt.String("Hi")
val[str]=str
vp.reset(val) --> gave error
Errors: TypeError: reset(): incompatible function arguments. The following argument types are supported:
1. (self: vp, value: Dict[std::String, std::String]) -> None
If I checked the type of val, it shows:
type of val is : <class 'dt.ssmap'>
So why the input argument (val) is taken as Dict, but the ssmap is taken as class of ssmap (but not Dict), Is there a way to match the two?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions