[C++-sig] Wrapping types with boost.python

Robert Parcus betoparcus at hotmail.com
Tue Jul 5 17:57:31 CEST 2011


Thank you Stephan, a few lines of your code have triggered a lot of sparks in my brain. >template <typename T>
>void define_vec2(char const *name)
>{
>   typedef tvec2<T> vec2_type;
>   class_<vec2_type> vec2(name);
>   float (vec2_type::*swizzle_1)(comp) = &vec2_type::swizzle;
>   vec2.def("swizzle", swizzle_1);
>   //...
>}
>
>and then call that function for all the value-types you want:
>
>   define_vec2<float>("fvec2");
>   define_vec2<int>("ivec2");
>   //...
I see that the template function approach is very useful for the number of value-types I have to work with (you guessed right), but I still have problems...
1) on the python interpreter, i have:	>>> fvec2	< class '_ext.fvec2' >	>>> int	< type 'int' >
Is there a standard way to make fvec2 become a real "type" in python, just like int?
2) I still can't do this from python 	>>> a = fvec2 (4.0,2.0) 
I realise that what I may be missing is .def("__init__", ... ) somewhere, but I don't know where, and how to initialize it properly. (
Also, I had to exclude the "swizzle" part(last 2 lines of the first section), because otherwise the program would no compile, but that's not the important part right?
Thanks again,Robert 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20110705/e2475853/attachment.html>


More information about the Cplusplus-sig mailing list