From: Eric W. <ewm...@gm...> - 2013-08-16 00:55:30
|
I am trying to bind a library (Chipmunk2D if anybody is curious). It has typedefs for the floating point type and a struct for points (a floating point for 'x' and another for 'y') The original intent was that the floating point type could be float or double depending on your platform. Additionally, the struct of points (cpVect) is defined differently on Apple platforms because they decided to leverage the built-in CGPoint struct: struct CGPoint { CGFloat x; CGFloat y; }; typedef struct CGPoint CGPoint; When on Apple, they typedef their cpVect to CGPoint. Otherwise they define it themselves. So in the Chipmunk headers, there is a lot of pre-processor dancing to figure out what to do automatically which looks like the following excerpt for flavor: #ifdef __APPLE__ #include "TargetConditionals.h" #endif #if ((TARGET_OS_IPHONE == 1) || (TARGET_OS_MAC == 1)) && (!defined CP_USE_CGPOINTS) #define CP_USE_CGPOINTS 1 #endif #if CP_USE_CGPOINTS == 1 #if TARGET_OS_IPHONE #import <CoreGraphics/CGGeometry.h> #elif TARGET_OS_MAC #include <ApplicationServices/ApplicationServices.h> #endif #if defined(__LP64__) && __LP64__ #define CP_USE_DOUBLES 1 #else #define CP_USE_DOUBLES 0 #endif #endif #ifndef CP_USE_DOUBLES // use doubles by default for higher precision #define CP_USE_DOUBLES 1 #endif #if CP_USE_DOUBLES /// Chipmunk's floating point type. /// Can be reconfigured at compile time. typedef double cpFloat; #else typedef float cpFloat; #endif #if CP_USE_CGPOINTS typedef CGPoint cpVect; #else typedef struct cpVect{cpFloat x,y;} cpVect; #endif Anyway, I am trying to write a SWIG .i file for this, but I'm stuck on how to handle this. If I just do the dumb thing and paste in the .h file, the generated code complains it doesn't know the size of cpVect as it is not defined. What strategies do you recommend for dealing with this? Thanks, Eric -- Beginning iPhone Games Development http://playcontrol.net/iphonegamebook/ |