Page 1 sur 1
Macro C => Macro PureBasic
Publié : dim. 19/déc./2010 19:37
par Atomo
Salut, j'essaie de convertir une macro écrite en C vers Purebasic :
C :
Code : Tout sélectionner
#define CP_DefineConstraintGetter(struct, type, member, name) \
static inline type \
struct##Get##name(const cpConstraint *constraint){ \
return ((struct *)constraint)->member; \
} \
PureBasic :
Code : Tout sélectionner
Macro CP_DefineConstraintGetter(struct, type, member, name)
Procedure.type struct#Get#name(*constraint.cpConstraint)
ProcedureReturn ((struct *)constraint)\member
EndProcedure
EndMacro
Je coince sur la ligne
ProcedureReturn, ce que j'ai fait ne fonctionne pas évidemment.
Merci de bien vouloir m'aider.

Re: Macro C => Macro PureBasic
Publié : lun. 20/déc./2010 8:25
par kernadec
bonjour Atomo
essaye voir de ce coté :
http://rosettacode.org/wiki/Category:PureBasic
il y a des exemples de translation de code ex:
http://rosettacode.org/wiki/Function_de ... #PureBasic
Cordialement
Re: Macro C => Macro PureBasic
Publié : lun. 20/déc./2010 20:37
par Atomo
Merci pour ton aide.
De ce que j'ai compris, c'est un opérateur de cast sur une structure, je vois pas du tout comment convertir ça en PB

Re: Macro C => Macro PureBasic
Publié : lun. 20/déc./2010 21:56
par djes
A mon avis tu n'étais pas très loin. Quand je ne sais pas, j'essaye de trouver où sert la fonction mais là ça ne nous aide pas beaucoup. Moi j'aurais fait ça...?
Code : Tout sélectionner
Macro CP_DefineConstraintGetter(struct, type, member, name)
Procedure.type struct#Get#name(*constraint.cpConstraint)
ProcedureReturn *constraint\member
EndProcedure
EndMacro
A priori dans PB on n'a pas le problème de cast dû au const.

Re: Macro C => Macro PureBasic
Publié : lun. 20/déc./2010 22:57
par Atomo
J'essaie de de faire un wrapper de la dernière version de Chipmunk (moteur physique 2D), les headers qui me posent problème sont
cpConstraint.h et
cpPinJoint.h
J'ai essayé de synthétiser le code en C :
Code : Tout sélectionner
typedef struct cpConstraint {
const cpConstraintClass *klass;
cpBody *a, *b;
cpFloat maxForce;
cpFloat biasCoef;
cpFloat maxBias;
cpDataPointer data;
} cpConstraint;
typedef struct cpPinJoint {
cpConstraint constraint;
cpVect anchr1, anchr2;
cpFloat dist;
cpVect r1, r2;
cpVect n;
cpFloat nMass;
cpFloat jnAcc, jnMax;
cpFloat bias;
} cpPinJoint;
#define CP_DefineConstraintGetter(struct, type, member, name) \
static inline type \
struct##Get##name(const cpConstraint *constraint){ \
return ((struct *)constraint)->member; \
} \
CP_DefineConstraintGetter(cpPinJoint, cpVect, anchr1, Anchr1);
Ce qui donnerai en PureBasic :
Code : Tout sélectionner
Structure cpConstraint
*klass.cpConstraintClass
*a.cpBody
*b.cpBody
maxForce.d
biasCoef.d
maxBias.d
*datas
EndStructure
Structure cpPinJoint
constraint.cpConstraint
anchr1.cpVect
anchr2.cpVect
dist.d
r1.cpVect
r2.cpVect
n.cpVect
nMass.d
jnAcc.d
jnMax.d
bias.d
EndStructure
Procedure cpPinJointGetAnchr1(*constraint.cpConstraint)
ProcedureReturn *constraint\anchr1
EndProcedure
Le problème c'est que la structure
cpConstraint n'a pas de membre
anchr1
Re: Macro C => Macro PureBasic
Publié : mar. 21/déc./2010 12:13
par Backup
hey !!
je viens de deplacer le topic de ICE
et toi tu recommence !
ça ne parle pas de Chipmunk ici !!
deplace ta reponse ici :
http://www.purebasic.fr/french/viewtopi ... =8&t=11313
ou change ton titre !
sinon ne vous etonnez âs de ne rien trouver avec le moteur de recherche du forum
