On Sun, 24 Apr 2005, John Morrison wrote:
> Are there any "convenience" macros/functions for defining a foreign
> function with a variable number of arguments, or do I need to define a
> clever Lisp function?
The latter. Lisp needs to know the foreign types of all the arguments
in order to be able to pass them to C (how many bits? signed or
unsigned?), and in case of varargs this cannot be trivially done:
the information is typically encoded in the non-varargs arguments
in some ad-hoc way.
Consider printf: to be able to pass the varargs lisp would first have
to parse the control string to determine the correct types. I think the
sanest way to do this would be something like
(defmacro printf (control &rest args)
`(alien-funcall ,(parse-printf-control control) ,@args))
where PARSE-PRINTF-CONTROL returns the appropriate (EXTERN-ALIEN ...)
form for the control string. Not that it needs to be a macro, though,
just a lot simpler that way, given that we don't support ALIEN-APPLY.
Cheers,
-- Nikodemus Schemer: "Buddha is small, clean, and serious."
Lispnik: "Buddha is big, has hairy armpits, and laughs."
|