Hi Robert,

On 2011-07-05 09:01, Robert Parcus wrote:

While exposing the functions has been pretty easy, I was not able yet to expose a single type. (I have been exposing the functions and specializing them only with int, double, etc types not the vectors and matrices, which are the most important types for me actually... I did it as a proof of concept, and because I'm stuck in this "exposing types" problem since a long time...)

Could you elaborate on what problems you have with exposing types ? What exactly did you try that didn't work ?


As an example, on line 38 of this code http://glm.g-truc.net/api-0.9.1/a00127_source.html is the definition of vec2. All glm types are pretty similar to this and if I could have some insights on how to wrap something like this the rest would be almost "not very hard" for me to do.

tvec2 itself isn't a type. You need to instantiate it to get a type that you can expose to Python. Then the normal rules should work just fine:

  class_<tvec2<float> > f_tvec2("fvec2");
  float (tvec2<float>::*swizzle_1)(comp) = &tvec2<float>::swizzle;
  f_tvec2.def("swizzle", swizzle_1);

I assume you'd like to do this for many different value-types, so it might be best to wrap this in a function template:

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");
  //...

HTH,
        Stefan

--

      ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to