PasteRack.org
Paste # 69797
2019-05-14 04:55:47

Fork as a new paste.

Paste viewed 141 times.


Embed:

#lang racket/base

(require ffi/unsafe
	 racket/list)

(define sdl-lib (ffi-lib "libSDL2" '("0" #f)))

(define (get-ffi-vararg name lib ret-type . args)
  (lambda rest
  (define c-rest (map (lambda (x)
			 (cond [(and (integer? x) (exact? x)) _int]
			       [(and (number? x) (real? x))   _double*]
			       [(string? x)  _string]
			       [(bytes? x)   _bytes]
			       [(symbol? x)  _symbol]
			       [else (error 'get-ffi-vararg
					    "don't know how to deal with ~e" x)]))
		       rest))
    (apply (get-ffi-obj name lib (_cprocedure (drop (append args c-rest) (length args)) ret-type)) rest)))

(define SDL_SetError (get-ffi-vararg "SDL_SetError" sdl-lib _void  _string))
(SDL_SetError)

(define SDL_GetError (get-ffi-obj "SDL_GetError" sdl-lib (_cprocedure '() _string)))
(displayln (SDL_GetError))