Lisp中的指针?

x13*_*13n 7 gtk common-lisp gdk

我最近开始学习Lisp并想编写一个使用gtk接口的程序.我已经安装了lambda-gtk绑定(在CMUCL上).我想在pixbuf上放置pixel/getpixel能力.但我发现我无法直接访问内存.(或者只是不知道怎么做)

函数(gdk:pixbuf-get-pixels pixbuf)给我一个数字 - 内存地址,我猜.在C++中,我可以轻松找到我需要的像素.有没有办法在Lisp中编写自己的putpixel?

dmi*_*_vk 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)
Run Code Online (Sandbox Code Playgroud)