Revision: 306
Author: roman_yakovenko
Date: 2006-07-17 01:10:52 -0700 (Mon, 17 Jul 2006)
ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=306&view=rev
Log Message:
-----------
adding FAQs documentation to py++
Modified Paths:
--------------
pyplusplus_dev/docs/faqs/faqs.rest
Modified: pyplusplus_dev/docs/faqs/faqs.rest
===================================================================
--- pyplusplus_dev/docs/faqs/faqs.rest 2006-07-13 08:27:50 UTC (rev 305)
+++ pyplusplus_dev/docs/faqs/faqs.rest 2006-07-17 08:10:52 UTC (rev 306)
@@ -59,6 +59,62 @@
That's all.
+-------------------------------------------------------
+How to expose function, which has hand-written wrapper?
+-------------------------------------------------------
+::
+
+ struct window_t{
+ ...
+ void get_size( int& height, int& widht ) const;
+ ...
+ };
+
+You can not expose ``get_size`` function as is - ``int`` is immutable type in
+Python. So, we need to create a wrapper to the function:
+::
+
+ boost::python::tuple get_size_wrapper( const window_t& win ){
+ int height(0), width( 0 );
+ win.get_size( height, widht );
+ return boost::python::make_tuple( height, width );
+ }
+
+::
+
+ class_<window_t>( ... )
+ .def( "get_size", &get_size_wrapper )
+ ...
+ ;
+
+Now, after you know how this problem is solved. I will show how this solution
+could be integrated with `pyplusplus`_.
+
+
+::
+
+ wrapper_code = """
+ static boost::python::tuple get_size( const window_t& win ){
+ int height(0), width( 0 );
+ win.get_size( height, widht );
+ return boost::python::make_tuple( height, width );
+ }
+ """
+
+::
+
+ registration_code = 'def( "get_size", &%s::get_size )' % window.wrapper_alias
+
+::
+
+ mb = module_builder_t( ... )
+ window = mb.class_( "window_t" )
+ window.member_function( "get_size" ).exclude()
+ window.add_wrapper_code( wrapper_code )
+ window.add_code( registration_code )
+
+That's all.
+
.. _`pyplusplus` : ./../pyplusplus.html
.. _`boost.python`: http://www.boost.org/libs/python/doc/index.html
.. _`Python`: http://www.python.org
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|