From fc74ddace39a4a6bde5ddb7c91b782898c2872b9 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 15 Aug 2009 00:56:34 +0000 Subject: [PATCH] add TypeHandle::make() --- dtool/src/dtoolbase/typeHandle.cxx | 20 ++++++++++++++++++++ dtool/src/dtoolbase/typeHandle.h | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/dtool/src/dtoolbase/typeHandle.cxx b/dtool/src/dtoolbase/typeHandle.cxx index 4075bc5380..74a180b526 100644 --- a/dtool/src/dtoolbase/typeHandle.cxx +++ b/dtool/src/dtoolbase/typeHandle.cxx @@ -19,6 +19,26 @@ // This is initialized to zero by static initialization. TypeHandle TypeHandle::_none; +#ifdef HAVE_PYTHON +//////////////////////////////////////////////////////////////////// +// Function: TypeHandle::make +// Access: Published +// Description: This special method allows coercion to a TypeHandle +// from a Python class object or instance. It simply +// attempts to call classobj.getClassType(), and returns +// that value (or raises an exception if that method +// doesn't work). +// +// This method allows a Python class object to be used +// anywhere a TypeHandle is expected by the C++ +// interface. +//////////////////////////////////////////////////////////////////// +PyObject *TypeHandle:: +make(PyObject *classobj) { + return PyObject_CallMethod(classobj, (char *)"getClassType", (char *)""); +} +#endif // HAVE_PYTHON + #ifdef DO_MEMORY_USAGE //////////////////////////////////////////////////////////////////// // Function: TypeHandle::get_memory_usage diff --git a/dtool/src/dtoolbase/typeHandle.h b/dtool/src/dtoolbase/typeHandle.h index dc6fbb0533..beecc306ba 100644 --- a/dtool/src/dtoolbase/typeHandle.h +++ b/dtool/src/dtoolbase/typeHandle.h @@ -65,6 +65,10 @@ class TypedObject; +#ifdef HAVE_PYTHON +#include "Python.h" +#endif + //////////////////////////////////////////////////////////////////// // Class : TypeHandle // Description : TypeHandle is the identifier used to differentiate @@ -98,6 +102,10 @@ PUBLISHED: INLINE TypeHandle(); INLINE TypeHandle(const TypeHandle ©); +#ifdef HAVE_PYTHON + static PyObject *make(PyObject *classobj); +#endif // HAVE_PYTHON + INLINE bool operator == (const TypeHandle &other) const; INLINE bool operator != (const TypeHandle &other) const; INLINE bool operator < (const TypeHandle &other) const;