[cffi-devel] Re: usage question

Luis Oliveira luismbo at gmail.com
Fri Oct 7 01:00:19 UTC 2005


Bruce Butterfield <bruce at open-tek.com> writes:
> // in include file:
> struct _TidyBuffer;
> typedef struct _TidyBuffer TidyBuffer;
> typedef void* TidyDoc;
>
> // example caller:
> TidyBuffer output = {0};
> TidyDoc tdoc = tidyCreate();
> ...
> tidySaveBuffer(tdoc, &output)
> ...

This C code (you don't show the declarations for tidyCreate() and
tidySaveBuffer() though) translates to something like this:

(use-package :cffi)

(defcstruct tidy-buffer
  ...)

(defctype tidy-doc :pointer)  ; if you prefer...

(defcfun ("tidyCreate" tidy-create) :tidy-doc)

(defcfun ("tidySaveBuffer" tidy-save-buffer) :void ;;?
  (doc tidy-doc)
  (out tidy-buffer))

;; caller
(with-foreign-object (output tidy-buffer)
  (let ((tdoc (tidy-create)))
    (tidy-save-buffer tdoc output)))

HTH

-- 
Luis Oliveira
luismbo (@) gmail (.) com
Equipa Portuguesa do Translation Project
http://www.iro.umontreal.ca/translation/registry.cgi?team=pt




More information about the cffi-devel mailing list