Wrap a function that takes class, and then get class typeid? #5013
Unanswered
UnidayStudio
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi! I'm the dev behind Cave Engine and we use pybind11 for scripting in it (thank y'all a lot for this lib!)
I'm facing an interesting design decision regarding its python API. In C++, my entities have an useful templated method to retrieve a given component:
I know it's not possible to wrap a templated class like that into pybind11, so we've been using our engine rtti to allow a similar method:
This way, we can do that in our scripts:
But as good as our rtti implementation is, string operations are getting quite expensive, so we are looking for an alternative. The ideal API for us would be something like that:
But for that, I'll need to be able to create a C++ function that takes that (I believe it's a
py::object
and retrieves its original class typeid's hash_code or something like that. But I'm struggling a bit to do this. Is it possible? If so, how can it be done?Minimal Reproducible Case
If you want a simple test case to better exemplify what I'm trying to do, here it is:
Then in python:
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions