[C++-sig] problem with declaring a pyste wrapper for a method in a nested class

scott snyder snyder at fnal.gov
Wed Oct 8 01:52:24 CEST 2003


hi -

I've run into a problem with declaring a pyste wrapper for a method
in a nested class.

Here's an example.


-- x.h --------------------------------------------------------------
struct A
{
  struct B
  {
    void foo();
  };
};
-- x.pyste ----------------------------------------------------------
A = Class ("A", "x.h")
foo_wrapper = Wrapper("foo_wrapper", "xxxfoo")
set_wrapper (A.B.foo, foo_wrapper)
---------------------------------------------------------------------

If i run pyste on this, here's the output:

// Boost Includes ==============================================================
#include <boost/python.hpp>
#include <boost/cstdint.hpp>

// Includes ====================================================================
#include <x.h>

// Using =======================================================================
using namespace boost::python;

// Module ======================================================================
BOOST_PYTHON_MODULE(x)
{
    scope* A_scope = new scope(
    class_< A >("A", init<  >())
        .def(init< const A& >())
    );

    class_< A::B >("B", init<  >())
        .def(init< const A::B& >())
        .def("foo", &foo_wrapper)
    ;

    delete A_scope;

}



Here, pyste has generated the reference to the wrapper, in the line

        .def("foo", &foo_wrapper)


But it has not inserted the requested wrapper text ('xxxfoo' in this example).

A fix follows.
thanks,
sss


Index: ClassExporter.py
===================================================================
RCS file: /cvsroot/boost/boost/libs/python/pyste/src/Pyste/ClassExporter.py,v
retrieving revision 1.14
diff -u -p -r1.14 ClassExporter.py
--- ClassExporter.py	6 Oct 2003 19:10:50 -0000	1.14
+++ ClassExporter.py	7 Oct 2003 23:46:24 -0000
@@ -189,6 +189,8 @@ class ClassExporter(Exporter):
         if declarations:
             codeunit.Write('declaration', declarations + '\n')
         declarations_outside = '\n'.join(self.sections['declaration-outside'])
+        for nested_unit in nested_codeunits:
+            declarations_outside += nested_unit.Section('declaration-outside')
         if declarations_outside:
             codeunit.Write('declaration-outside', declarations_outside + '\n')





More information about the Cplusplus-sig mailing list