(import (scheme) (chicken base) (chicken syntax) (srfi 152)) (define (snake-upcase in) (string-map (lambda (c) (if (char=? #\- c) #\_ (char-upcase c))) in)) (define-syntax define-sdl-flag (er-macro-transformer (lambda (exp rename compare) (let ((flag (cadr exp))) `(begin (export ,flag) (define ,flag (foreign-value ,(string-append "SDL_" (snake-upcase (symbol->string flag))) unsigned-int32))))))) (define-syntax define-sdl-enum-values (er-macro-transformer (lambda (exp rename compare) (let ((prefix (cadr exp)) (type (caddr exp)) (enum-labels (cdddr exp))) `(begin ,@(map (lambda (enum-label) (let ((full-str (string-append (symbol->string prefix) "-" (symbol->string enum-label)))) `(begin (export ,(string->symbol full-str)) (define ,(string->symbol full-str) (foreign-value ,(string-append "SDL_" (snake-upcase full-str)) ,type))))) enum-labels))))))