[Python-Dev] Re: About Pyrex

David Abrahams David Abrahams" <david.abrahams@rcn.com
Wed, 10 Apr 2002 01:00:09 -0500


----- Original Message -----
From: "Ralf W. Grosse-Kunstleve" <rwgk@cci.lbl.gov>

> The most important feature for me is that both the compiled code and
> the interpreted code look nice and are extensible.
> The second most important feature is that all you need is Python
> and C++. There is no third (little) language to learn (as with
> SWIG).

As libraries start to take more advantage of template metaprogramming
techniques, their interface starts to approach a language definition.
How different, really, is the following from being an IDL?

BOOST_PYTHON_MODULE_INIT(back_reference_ext)
{
    module("back_reference_ext")
        .def("copy_Y", copy_Y,
return_value_policy<copy_const_reference>())
        .def("copy_Z", copy_Z,
return_value_policy<copy_const_reference>())
        .def("x_instances", &X::count)
        .add(
            class_<Y>("Y")
            .def_init(args<int>())
            .def("value", &Y::value)
            .def("set", &Y::set)
            )

        .add(
            class_<Z,std::auto_ptr<Z> >("Z")
            .def_init(args<int>())
            .def("value", &Z::value)
            .def("set", &Z::set)
            )
        ;
}

The real advantage to using the C++ compiler as opposed to intermediate
language is that we can be sure it is up to the job of dealing with any
C/C++ language constructs we throw at it.

-Dave