-(defmacro def-callback-marshal (name (return-type &rest args))
- (let ((names (loop
- for arg in args
- collect (if (atom arg) (gensym) (first arg))))
- (types (loop
- for arg in args
- collect (if (atom arg) arg (second arg)))))
- `(defcallback ,name (,return-type ,@(mapcar #'list names types)
- (callback-id unsigned-int))
- (invoke-callback callback-id ',return-type ,@names))))
+(defmacro define-callback-marshal (name return-type args &key (callback-id :last))
+ (let* ((ignore ())
+ (params ())
+ (names (loop
+ for arg in args
+ collect (if (or
+ (eq arg :ignore)
+ (and (consp arg) (eq (first arg) :ignore)))
+ (let ((name (gensym "IGNORE")))
+ (push name ignore)
+ name)
+ (let ((name (if (atom arg)
+ (gensym (string arg))
+ (first arg))))
+ (push name params)
+ name))))
+ (types (loop
+ for arg in args
+ collect (cond
+ ((eq arg :ignore) 'pointer)
+ ((atom arg) arg)
+ (t (second arg))))))
+ `(define-callback ,name ,return-type
+ ,(ecase callback-id
+ (:first `((callback-id unsigned-int) ,@(mapcar #'list names types)))
+ (:last `(,@(mapcar #'list names types) (callback-id unsigned-int))))
+ (declare (ignore ,@ignore))
+ (invoke-callback callback-id ',return-type ,@(nreverse params)))))