From 6a32620db3d31b18d272a2f0f3d704dab02000bb Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Fri, 2 Oct 2015 00:42:33 +0200 Subject: [PATCH] convenience function to create a pybind::handle<> to the python version of a C++ type --- include/pybind/pytypes.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/pybind/pytypes.h b/include/pybind/pytypes.h index 6d98d7d4f..4f70bbd23 100644 --- a/include/pybind/pytypes.h +++ b/include/pybind/pytypes.h @@ -404,5 +404,13 @@ inline handle get_object_handle(const void *ptr) { return it->second; } +inline handle get_type_handle(const std::type_info &tp) { + auto instances = get_internals().registered_types; + auto it = instances.find(&tp); + if (it == instances.end()) + return handle(); + return handle((PyObject *) it->second.type); +} + NAMESPACE_END(detail) NAMESPACE_END(pybind)