[C++-sig] Getting a Python type object for a c++ type in wrapper code...
Nick Rasmussen
nick at ilm.com
Tue Oct 4 20:53:42 CEST 2005
Perhaps something like:
#include <Python.h>
#include <boost/python.hpp>
using namespace boost::python;
struct Foo {
};
struct Bar {
static object fooType;
};
object Bar::fooType;
BOOST_PYTHON_MODULE(test)
{
class_<Foo> fooType("Foo");
Bar::fooType = fooType;
class_<Bar> barType("Bar");
barType
.def_readonly("fooType",&Bar::fooType);
}
-nick
On Tue, 04 Oct 2005, Alex Mohr wrote:
> Hi folks,
>
> I'm a relative boost.python newbie but I've been doing a ton with it and
> I'm having a blast. Thanks for such an awesome package.
>
> Here's my first newbie question.
>
> Suppose I have two C++ classes that I'm wrapping -- Foo and Bar. In the
> wrapper for Bar, I want there to be an attribute which holds the type
> Foo. That is, from python I wan to be able to say:
>
> >>> Module.Bar.fooType == Module.Foo
> True
>
> Something like def_readonly("fooType", <var-which-holds-type-for-Foo>)
> would be ideal. I'd also like to be able to do this for python types,
> like python's float. Is there a simple way to do this in my
> Boost.Python code?
>
> Thanks,
>
> Alex
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
More information about the Cplusplus-sig
mailing list