[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-cpp-sig
Subject:    [C++-sig] Static functions in Boost.Python
From:       mwyatt () wi ! rr ! com (Mike Wyatt)
Date:       2006-05-19 3:36:50
Message-ID: 446D3D52.104 () wi ! rr ! com
[Download RAW message or body]

Mike Wyatt wrote:

> How can I define my C++ class' static functions in Boost.Python?  I 
> googled the subject quite a bit, and failed to find anything useful, 
> except for this little mailing between chuzo okada and Dave:
>
> http://mail.python.org/pipermail/c++-sig/2002-July/001635.html
>
> My guess is that this is not supported, since Python has no concept of 
> static methods (right?).  If that is the case, should I simply declare 
> "global" functions that use my Matrix class, and bind them in the 
> BOOST_PYTHON_MODULE(matrix) block?
>
> Here is an excerpt of my Matrix class and Boost.Python mapping:
>
> class Matrix
> {
> public:
>     /* other member functions */
>     static Matrix* Translation(float x, float y, float z);
> private:
>     /* private variables */
> }
>
> BOOST_PYTHON_MODULE(matrix)
> {
>     class_<Matrix>("Matrix")
>         /* other*/
>         .def("Translation", &Matrix::Translation)
>     ;
> }
>
> Thanks,
>
> Mike
>
>------------------------------------------------------------------------
>
>_______________________________________________
>C++-sig mailing list
>C++-sig at python.org
>http://mail.python.org/mailman/listinfo/c++-sig
>  
>
>------------------------------------------------------------------------
>
>No virus found in this incoming message.
>Checked by AVG Free Edition.
>Version: 7.1.392 / Virus Database: 268.6.0/342 - Release Date: 5/17/2006
>  
>
I figured it out, thanks to pyste:

BOOST_PYTHON_MODULE(matrix)
{
    class_< Matrix >("Matrix")
         /* other */
        .def("Translation", &Matrix::Translation, 
return_value_policy<manage_new_object>() )
        .staticmethod("Translation")
    ;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/c++-sig/attachments/20060518/b35acb07/attachment.htm 

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic