[Ecls-list] ffi C calling help

Franco Grex francogrex at mail.com
Fri Feb 27 20:57:22 UTC 2009


Hi I am using ECL ffi to call a C function "chelper.c" which should
output some data into an ECL list "my-list". I want to return the values
of the c function directly into ECL but now I can't, I am having to pass
thru an external file "out.txt". Is there a way to pass the values of the
C function directly into ECL list without an intermediate writing to an
external file first? Thanks. The example files are below:;;;;;;;;;
chelper.c
;;;;;;;;
#include <stdio.h>
FILE *f1;
int outfn(void)
{
int n;
f1 = fopen ("c:/out.txt", "wt");
for (n = 0; n<20; ++n)
{
printf ("%d\n",n);
fprintf (f1, "%d\n", n);
}
fclose (f1);
} ;;;;;;::
test.lisp
;;;;;;;;
(defun my-run (x)
(ffi:clines "#include <c:/chelper.c>")
(ffi:c-inline(x) (:int)  :int "outfn()" :one-liner t))
;;(compile-file "c:/test.lisp")
;;(load "c:/test.fas")
(my-run nil)
(with-open-file (stream "c:/out.txt" :direction :input)
(setq my-list (loop for input = (read stream nil stream)
until (eq input stream) collect input)))
my-list

-- 
Be Yourself @ mail.com!
Choose From 200+ Email Addresses
Get a Free Account at www.mail.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20090227/65efdf34/attachment.html>


More information about the ecl-devel mailing list