[Prev][Next][Index][Thread]

Re: Issues with GD



> From: Nolan Darilek <nolan@ethereal.dhis.org>
> 
> Hmm, are there any FFI examples/tutorials? How difficult is it to
> hand-code FFI if given a header? I've hand-coded working versions of
> basic SDL functionality in SWIG, so if this route works, then I may be
> willing to start hacking at a few additional libraries and making the
> work available.

That would be great!
It can get tedious if you're coding more than a few dozen functions, but
once you get the hang of it it's quite easy.
The main problem is compound types. You'll need to make struct types and
accessors and pass in their raw-value to call-out.
I'm just finishing converting Patrick Beard's old Mindy Mac Toolbox library
to d2c, here's some examples, I can send more if you're interested.


define functional class <Point> (<statically-typed-pointer>)
end class;

define method content-size( cls == <Point> )
=>( result :: <integer> )
    4;
end method content-size;

define method initialize( pt :: <Point>, #key v = 0, h = 0)
=> ( result :: <Point> )
  point-v(pt) := v;
  point-h(pt) := h;
  pt;
end method initialize;

define method point-v (pt :: <Point>) => (v :: <integer>);
    signed-short-at(pt, offset: 0);
end method point-v;

define method point-v-setter (value :: <integer>, pt :: <Point>) => (value
:: <integer>);
    signed-short-at(pt, offset: 0) := value;
end method point-v-setter;

// Same for point-v

define method GetNewWindow( id :: <integer> )
=> ( result :: <WindowPtr> )
    let ptr = call-out( "GetNewCWindow", ptr:, short: id, ptr: 0, ptr: -1 );
    make( <WindowPtr>, pointer: ptr );
end method GetNewWindow;

define method TrackGoAway( window :: <WindowPtr>, startPoint :: <Point> )
=> ( result :: <boolean> )
    call-out("trackgoaway", unsigned-char:, ptr: window.raw-value, ptr:
startPoint.raw-value );
end method TrackGoAway;

// etc...

- Rob.




Follow-Ups: References: