Subject: [clisp-list] ffi intro (c-callouts)

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Tue Aug 20 06:40:06 2002

Hi,

Leland Hovey asks:

>I need to find the documentation describing the basic techniques
>(step by step) of using c-callouts.
>Specifically, what is the syntax,
I believe this is covered in enough depth in the impnotes.txt. Do you need more examples (found at the bottom of the FFI chapter)?

>where would a c function reside,
In an object module or shared library that you need to open or link against the CLISP binary.

> and how can I inform clisp about the c
>function's location?
Usually done internally via DEF-CALL-OUT or similar forms. These are wrappers that'll try to find the location for you. (If you pass from ffi intro to expert level you could even construct foreign function objects on the fly :)

>I've found a little information in the implementation notes 
>(i.e., calling
>out to gethostname) but this example doesn't work for me.

It would help us if you could be more/very specific about the exact nature of the problem.
Having examples work is a good start for learning.

Do the modules in directories modules/foo/bar help you?

Also, what OS and CLISP are your using?

Regards,
	Jorg Hohle.

---

From: Leland Hovey <[email-masked]>
Date: Tue Aug 20 07:29:01 2002

So my OS is Solaris 8 and I've got clisp-2.29.

function definition (file c-callout.lisp):
(ffi:def-c-call-out gethostname
    (:arguments (name (ffi:c-ptr (ffi:c-array-max ffi:char 256))
                      :out :alloca)
                      (len ffi:int))
    (:return-type ffi:int))
-------------------------------------------------------------------
result from clisp:
(load "c-callout.lisp")
;; Loading file /home/cisgrad/lhovey/lisp/c-callout.lisp ...
*** - FFI::LOOKUP-FOREIGN-FUNCTION: A foreign function "gethostname" does
not exist
------------------------------------------------------------------

> Do the modules in directories modules/foo/bar help you?
I searched the clisp-2.29 directory branch but there isn't a
modules/foo/bar subdirectory.  Could I have only a partial install?

-L

---

From: "John K. Hinsdale" <[email-masked]>
Date: Tue Aug 20 07:47:05 2002

> ... 

Might be that you are not running the "full" clisp which is the one
that links in the extra C funcs.  Go the subdir "src/full" and in there
run 
	./lisp.run -M lispinit.mem

and load your lisp file.

Also, don't use the filename "c-callout.c" for your C funcs - your
code will get clobbered when "c-callout.lisp" is compiled into
"c-callout.c"  Use some other name for your C files.

 > modules/foo/bar subdirectory.  Could I have only a partial install?

I love the quoting problem.  He means modules/<foo>/<bar> with example
being "modules/regexp" ...

---
John Hinsdale, Alma Mater Software, Inc., Tarrytown, NY 10591-3710 USA
[email-masked] | http://www.alma.com/staff/hin | +1 914 631 4690