[Ecls-list] Declaring functions with variable arguments from C
Juan Jose Garcia Ripoll
juan.ripoll at mpq.mpg.de
Mon Jun 9 10:28:15 UTC 2003
On Monday 09 June 2003 18:42, Julian St. wrote:
> Hello,
>
> how would I declare a C function (and use the arguments) that would look
> from Lisp somewhat like
>
> (defun emit-print (event &rest cmds) ...
>
> I hope I am correct with my approach using cl_def_c_function_va() ?
If your function (Let us call it "my_c_fun()") has a prototype like
cl_object my_c_fun(int narg, ...)
and it expects only to receive values of type "cl_object", then you can use
cl_def_c_function_va(c_string_to_object("MY-C-FUN"), my_c_fun)
to assign the function to the lisp symbol MY-C-FUN. After the call to
"cl_def..." the function may be used in the Lisp world. The argument NARG
will tell the function how many values it should retrieve.
For retrieving optional arguments in a safe way, you should use the cl_va_*
interface. This works as follows:
cl_object a_test_function(int narg, ...) {
cl_va_list args;
cl_va_start(args, narg, narg, 0);
cl_object output = Cnil;
for (i = 0; i<narg; i++)
output = CONS(output, cl_va_arg(args));
return1(output);
}
The whole interface for defining functions, etc, is one of the most "unstable"
features of ECL, in the sense that it is prone to change in the near future.
Since I use it very little, I will welcome (and probably implement :-) any
suggestions to improve its usability.
Best regards,
Juanjo
--
Max-Planck-Institut fuer Quantenoptik +49/(0)89/32905-345
Hans-Kopfermann-Str. 1, D-85748 www.mpq.mpg.de/Theorygroup/CIRAC/
Garching b. Muenchen, Germany Juan.Ripoll at mpq.mpg.de
More information about the ecl-devel
mailing list