|
| 1 | +Auto_Function_Wrapper: Clean up argument definitions |
| 2 | + |
| 3 | +Implicit and other type conversions: |
| 4 | + |
| 5 | + The idea here is that we can tell Rice which types have been defined to have |
| 6 | + automatic conversions. For example, Ogre::Degree and Ogre::Radian are defined |
| 7 | + to be used interchangably, and any numerical conversions happen in each class. |
| 8 | + |
| 9 | + boost::python exposes a completely seperate declaration method: implicitly_convertible<from, to> |
| 10 | + I'm going to try having it as a method on Data_Type, but I may need to go the same route |
| 11 | + depending on if bi-directional requires this, say: |
| 12 | + |
| 13 | + implicitly_convertible<Ogre::Degree, Ogre::Radian>(); |
| 14 | + implicitly_convertible<Ogre::Radian, Ogre::Degree>(); |
| 15 | + |
| 16 | + Due to Rice's and Ruby's differing handling of defined types and fundamental types (int, float, etc), |
| 17 | + special care needs to be taken to ensure both conversions work |
| 18 | + |
| 19 | + I want to be able to do: |
| 20 | + |
| 21 | + struct Real |
| 22 | + { |
| 23 | + Real(int x) |
| 24 | + : v(x) |
| 25 | + {} |
| 26 | + |
| 27 | + operator int() const |
| 28 | + { |
| 29 | + return v; |
| 30 | + } |
| 31 | + |
| 32 | + int v; |
| 33 | + }; |
| 34 | + |
| 35 | + define_class<Real>("Real") |
| 36 | + .define_constructor(Constructor<Real, int>()) |
| 37 | + .implicit_cast_to<int>(); |
| 38 | + |
| 39 | + or if there were a defined type that Real converts to and from: |
| 40 | + |
| 41 | + define_class<Real>("Real") |
| 42 | + .define_constructor(Constructor<Real, int>()) |
| 43 | + .implicit_cast_to<Fake>(); |
| 44 | + |
| 45 | + define_class<Fake>("Fake") |
| 46 | + .define_constructor(Constructor<Fake, int>()) |
| 47 | + .implicit_cast_to<Real>(); |
| 48 | + |
| 49 | + So the steps I'll need to take to make this work correctly are as follows: |
| 50 | + |
| 51 | + T from_ruby(Rice::Object x) |
| 52 | + - Check for direct match (exists) |
| 53 | + - Change casters to a multimap |
| 54 | + - Build new caster for implicit type conversion |
| 55 | + - Might need two ways of this: constructor or cast method. |
| 56 | + |
| 57 | + - Check for any implicit casts for type T |
| 58 | + - Try to build the list so that I don't have to actually cast anything |
| 59 | + unless I know it's the right type to cast to |
| 60 | + - How do I know what type I'm casting from? (the case of Real being given a FixNum) |
| 61 | + - Defined types to Defined types will be much simpler I believe |
| 62 | + |
0 commit comments