Thread overview
Help converting a headerfile to D
May 16, 2005
Oliver
May 19, 2005
Chris Sauls
May 16, 2005
Hello there !

I am converting a GUI C-API to D and have 2 questions concerning headerfiles.

1. How would I convert these ?

typedef void (*WindowFunc)      (Window *w);
typedef void (*WindowMouseFunc) (Window *w, int buttons, Point xy);
typedef void (*WindowKeyFunc)   (Window *w, unsigned long key);
typedef void (*WindowDrawFunc)  (Window *w, Graphics *g);

typedef void (*ControlFunc)     (Control *c);
typedef void (*MouseFunc)       (Control *c, int buttons, Point xy);
typedef void (*KeyFunc)         (Control *c, unsigned long key);
typedef void (*DrawFunc)        (Control *c, Graphics *g);

typedef void (*MenuAction)      (MenuItem *mi);

typedef void (*TimerAction)     (Timer *t);

2. And these ?

#define app_copy_rect(g,dp,src,sr) ((g)->copy_rect((g),(dp),(src),(sr)))
#define app_fill_rect(g,r)         ((g)->fill_rect((g),(r)))
#define app_draw_utf8(g,p,utf8,nb) ((g)->draw_utf8((g),(p),(utf8),(nb)))
#define app_draw_line(g,p1,p2)     ((g)->draw_line((g),(p1),(p2)))
(g is some struct)


Help would be greatly appreciated.

Regards, Oliver


May 16, 2005
For the first section, change "unsigned long" to "uint" and you're done.  Unless you don't want them to be typedefs, but rather aliases - in this case, change "typedef" to "alias".

For the second, write them as functions (which will be inlined):

whatever app_copy_rect(whatever g, whatever dp, whatever src, whatever sr)
{
	return g.copy_rect(g, dp, src, sr);
}

-[Unknown]


> Hello there !
> 
> I am converting a GUI C-API to D and have 2 questions concerning headerfiles.
> 
> 1. How would I convert these ? 
> 
> typedef void (*WindowFunc)      (Window *w);
> typedef void (*WindowMouseFunc) (Window *w, int buttons, Point xy);
> typedef void (*WindowKeyFunc)   (Window *w, unsigned long key);
> typedef void (*WindowDrawFunc)  (Window *w, Graphics *g);
> 
> typedef void (*ControlFunc)     (Control *c);
> typedef void (*MouseFunc)       (Control *c, int buttons, Point xy);
> typedef void (*KeyFunc)         (Control *c, unsigned long key);
> typedef void (*DrawFunc)        (Control *c, Graphics *g);
> 
> typedef void (*MenuAction)      (MenuItem *mi);
> 
> typedef void (*TimerAction)     (Timer *t);
> 
> 2. And these ?
> 
> #define app_copy_rect(g,dp,src,sr) ((g)->copy_rect((g),(dp),(src),(sr)))
> #define app_fill_rect(g,r)         ((g)->fill_rect((g),(r)))
> #define app_draw_utf8(g,p,utf8,nb) ((g)->draw_utf8((g),(p),(utf8),(nb)))
> #define app_draw_line(g,p1,p2)     ((g)->draw_line((g),(p1),(p2)))
> (g is some struct)
> 
> 
> Help would be greatly appreciated.
> 
> Regards, Oliver
> 
> 
May 17, 2005
"Unknown W. Brackets" <unknown@simplemachines.org> wrote in message news:d68ur1$pq7$1@digitaldaemon.com...
> For the first section, change "unsigned long" to "uint" and you're done. Unless you don't want them to be typedefs, but rather aliases - in this case, change "typedef" to "alias".

Ooh, and if you're passing in class refs (like Window and Control), be sure to remove the pointer symbol (*) in the parameter lists.  If they're structs, though, leave the pointer symbol there.


May 19, 2005
Jarrett Billingsley wrote:
> Ooh, and if you're passing in class refs (like Window and Control), be sure to remove the pointer symbol (*) in the parameter lists.  If they're structs, though, leave the pointer symbol there. 

Or get rid of the pointer symbol anyway and use an inout parameter.

-- Chris Sauls