Changeset 33298 in project


Ignore:
Timestamp:
04/18/16 02:31:34 (4 years ago)
Author:
John Foerch
Message:

Wrapping simple structs: add a finalizer in foreigners example

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/Wrapping simple c structs

    r33297 r33298  
    4141
    4242<enscript highlight="scheme">
    43 (use foreigners)
     43(use foreigners lolevel)
    4444
    4545(foreign-declare "#include <SDL/SDL.h>")
     
    5151  (unsigned-short h sdl-rect-h sdl-rect-h-set!))
    5252
    53 (define make-sdl-rect
    54   (foreign-lambda* sdl-rect
    55       ((short x) (short y) (unsigned-short w) (unsigned-short h))
    56     "SDL_Rect* r = (SDL_Rect*)malloc(sizeof(SDL_Rect));"
    57     "r->x = x;"
    58     "r->y = y;"
    59     "r->w = w;"
    60     "r->h = h;"
    61     "C_return(r);"))
     53(define (make-sdl-rect x y w h)
     54  (let ((r ((foreign-lambda* sdl-rect
     55                ((short x) (short y) (unsigned-short w) (unsigned-short h))
     56              "SDL_Rect* r = (SDL_Rect*)malloc(sizeof(SDL_Rect));"
     57              "r->x = x;"
     58              "r->y = y;"
     59              "r->w = w;"
     60              "r->h = h;"
     61              "C_return(r);")
     62            x y w h)))
     63    (set-finalizer! r free)
     64    r))
    6265
    6366(define a (make-sdl-rect 10 20 30 40))
Note: See TracChangeset for help on using the changeset viewer.