Next: , Previous: , Up: Tutorial   [Contents][Index]

4.10 A complete FFI?

With all options finally set and a medium-level interface developed, we can finish the definition and retrieve, as is done in the tutorial.

  (defcfun "curl_easy_perform" curl-code
    (handle easy-handle))
CFFI-USER> (with-output-to-string (contents)
             (let ((*easy-write-procedure*
                     (lambda (string)
                       (write-string string contents))))
               (declare (special *easy-write-procedure*))
               (curl-easy-perform *easy-handle*)))
Now fear, comprehensively</P>

Of course, that itself is slightly unwieldy, so you may want to define a function around it that simply retrieves a URL. I will leave synthesis of all the relevant REPL forms presented thus far into a single function as an exercise for the reader.

The remaining sections of this tutorial explore some advanced features of CFFI; the definition of new types will receive special attention. Some of these features are essential for particular foreign function calls; some are very helpful when trying to develop a Lispy interface to C.