[C++-sig] How to use a C++ function with pointer/length arguments in Python

Huang You Gong huangyougong at gmail.com
Wed Jan 16 09:21:54 CET 2008


 Hi,

in c++ there are codes like this:

*struct x*
*{*
*    int a;*
*    short b;*
*    short c;*
*};*
*struct y*
*{*
*    byte a;*
*    byte b;*
*    byte c;*
*};*
*void foo( byte * data, int len ){ //... }*

in boost_python_module, I defined it as:

*class_< x >( "x" )  * *    .def_readwrite( "a", &x::a )  * *
.def_readwrite( "b", &x::b )  * *    .def_readwrite( "c", &x::c )*
*.def( "foo", foo )*

then in python, how to write code to send x or y object to foo? in c++ way,
it should be like this:

*x X;*
*foo( &X, sizeof( x ) );*
*y Y;*
*foo( &Y, sizeof( y ) );*

-- 
Thanks
Huang You Gong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080116/ffac665a/attachment.htm>


More information about the Cplusplus-sig mailing list