PasteRack.org
Paste # 22594
2019-05-14 04:55:26

Fork as a new paste.

Paste viewed 127 times.


Embed:

  1. #lang racket/base
  2.  
  3. (require ffi/unsafe
  4.          racket/list)
  5.  
  6. (define sdl-lib (ffi-lib "libSDL2" '("0" #f)))
  7.  
  8. (define (get-ffi-vararg name lib ret-type . args)
  9.   (lambda rest
  10.   (define c-rest (map (lambda (x)
  11.                          (cond [(and (integer? x) (exact? x)) _int]
  12.                                [(and (number? x) (real? x))   _double*]
  13.                                [(string? x)  _string]
  14.                                [(bytes? x)   _bytes]
  15.                                [(symbol? x)  _symbol]
  16.                                [else (error 'get-ffi-vararg
  17.                                             "don't know how to deal with ~e" x)]))
  18.                        rest))
  19.     (apply (get-ffi-obj name lib (_cprocedure (drop (append args c-rest) (length args)) ret-type)) rest)))
  20.  
  21. (define SDL_SetError (get-ffi-vararg "SDL_SetError" sdl-lib _void  _string))
  22. (SDL_SetError)
  23.  
  24. (define SDL_GetError (get-ffi-obj "SDL_GetError" sdl-lib (_cprocedure '() _string)))
  25. (displayln (SDL_GetError))

=>

eval:2:0: ?: access disallowed by code inspector to

protected variable from module:

"/home/pasterack/racket68/collects/ffi/unsafe.rkt"

  at: ffi-lib

  in: get-ffi-lib

eval:3:0: _double*: access disallowed by code inspector to

protected variable from module: '#%foreign

  in: _double*

eval:4:0: _void: access disallowed by code inspector to

protected variable from module: '#%foreign

  in: _void

SDL_SetError: undefined;

 cannot reference an identifier before its definition

  in module: 'm

eval:6:0: get-ffi-obj: access disallowed by code inspector

to protected variable from module:

"/home/pasterack/racket68/collects/ffi/unsafe.rkt"

  in: get-ffi-obj

SDL_GetError: undefined;

 cannot reference an identifier before its definition

  in module: 'm