27.11.2014 Views

CFFI User Manual - Common Lisp.net

CFFI User Manual - Common Lisp.net

CFFI User Manual - Common Lisp.net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6: Foreign Types 34<br />

;; Initialize the slots<br />

(setf (foreign-slot-value ptr ’point ’x) 42<br />

(foreign-slot-value ptr ’point ’y) 42)<br />

;; Return a list with the coordinates<br />

(with-foreign-slots ((x y) ptr point)<br />

(list x y)))<br />

⇒ (42 42)<br />

;; Using the :size and :offset options to define a partial structure.<br />

;; (this is useful when you are interested in only a few slots<br />

;; of a big foreign structure)<br />

(defcstruct (foo :size 32)<br />

"Some struct with 32 bytes."<br />

; <br />

(x :int :offset 16) ; an int at offset 16<br />

(y :int) ; another int at offset 16+sizeof(int)<br />

; <br />

(z :char :offset 24)) ; a char at offset 24<br />

; <br />

<strong>CFFI</strong>> (foreign-type-size ’foo)<br />

⇒ 32<br />

;;; Using :count to define arrays inside of a struct.<br />

(defcstruct video_tuner<br />

(name :char :count 32))<br />

See Also<br />

[foreign-slot-pointer], page 46<br />

[foreign-slot-value], page 47<br />

[with-foreign-slots], page 55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!