[C++-sig] Static functions in Boost.Python
Mike Wyatt
mwyatt at wi.rr.com
Fri May 19 05:36:50 CEST 2006
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/cplusplus-sig/attachments/20060518/b35acb07/attachment.htm>
More information about the Cplusplus-sig
mailing list