2009-11-16 2 views
7

나는 최근 Lisp을 배우기 시작했고 gtk 인터페이스를 사용하는 프로그램을 작성하려고했다. 나는 lambda-gtk 바인딩 (CMUCL에)을 설치했다. pixbuf에서 putpixel/getpixel 기능을 사용하고 싶습니다. 하지만 나는 액세스 메모리를 지시 할 수 없다는 것을 알았다. (또는 방법을 모르겠다)Lisp의 포인터?

함수 (gdk : pixbuf-get-pixels pixbuf)는 숫자 - 메모리 주소를 반환합니다. C++에서는 필요한 픽셀을 쉽게 얻을 수 있습니다. 내 자신의 putpixel을 Lisp에 작성하는 방법이 있습니까?

답변

7

Lisp에서 C 라이브러리에 액세스하고 직접 메모리 액세스를 수행하는 현대적이고 이식 가능한 방법은 CFFI입니다.

이처럼 사용할 수 있습니다

>(defparameter *p* (cffi:foreign-alloc :unsigned-char :count 10)) 
;; allocate 10 bytes 
*P* 
> (setf (cffi:mem-aref *p* :unsigned-char 0) 10) 
;; access *p* as an array of bytes and set its 0th element to 10 
10 
> (cffi:mem-aref *p* :unsigned-char 0) 
;; access *p* as an array of bytes and take its 0th element 
10 
> (cffi:make-pointer 123) 
;; make a pointer that points to given address 
#.(SB-SYS:INT-SAP #X0000007B)