Convert arguments and return values
define-binding** to accept optional procedures which will be used to convert arguments before passing them to the C function, or will be used to convert the C function's return value.
A similar effect can already be accomplished using
define-foreign-type, but this would allow for more fine-grained control of conversion or validation for each individual argument or return value.
The API might look like this:
(define-binding (SCHEME-NAME FUNC_NAME) return: (RETURN-TYPE => RETCONVERT) args: ((ARG-TYPE ARG_NAME => ARGCONVERT) ...))
And would expand to something like:
(define (SCHEME-NAME ARG_NAME ...) (RETCONVERT ((foreign-lambda RETURN-TYPE FUNC_NAME ARG-TYPE ...) (ARGCONVERT ARG_NAME) ...)))
RETCONVERT or any
ARGCONVERT is omitted, that value is not converted. Ideally the macro should generate the minimal code necessary, so a binding with no
ARGCONVERTs would expand to:
(define (SCHEME-NAME ARG_NAME ...) ((foreign-lambda RETURN-TYPE FUNC_NAME ARG-TYPE ...) ARG_NAME ...))
Or, if this is significantly more efficient, so that it is worth losing the argument names when the procedure is written in the REPL, expand to:
(define SCHEME-NAME (foreign-lambda RETURN-TYPE FUNC_NAME ARG-TYPE ...))