You are looking at historical revision 18112 of this page. It may differ significantly from its current revision.

Here's a little example wrapping c structs in a scheme blob. Since they might be moved around by garbage collection, you cannot store pointers to them, but for simple structs it should suffice.

(use lolevel)

(foreign-declare "#include <SDL/SDL.h>")

;; SDL_Rect is defined thusly:
;typedef struct{
;  Sint16 x, y;
;  Uint16 w, h;
;} SDL_Rect;

(define sizeof-SDL_Rect (foreign-value "sizeof(SDL_Rect)" int))

(define-record sdl-rect buffer)

(define-foreign-type sdl-rect scheme-pointer sdl-rect-buffer)

(define sdl-rect-x
  (foreign-lambda* short ((sdl-rect rect))

(define sdl-rect-x-set!
  (foreign-lambda* void ((sdl-rect rect) (short value))
    "((SDL_Rect*)rect)->x = value;"))

;; behold

(define foo (make-sdl-rect (make-blob sizeof-SDL_Rect)))
(sdl-rect-x-set! foo 30)
(sdl-rect-x foo) ==> 30