Lisp 中的指针?

发布于 2024-08-11 06:59:01 字数 244 浏览 5 评论 0原文

我最近开始学习 Lisp,想编写一个使用 gtk 接口的程序。我已经安装了 lambda-gtk 绑定(在 CMUCL 上)。我想在 pixbuf 上具有 putpixel/getpixel 功能。但我发现我无法直接访问内存。 (或者只是不知道如何)

函数(gdk:pixbuf-get-pixels pixbuf)返回我一个数字 - 我猜是内存地址。在 C++ 中我可以轻松获得我需要的像素。有什么方法可以用 Lisp 编写我自己的 putpixel 吗?

I've started learning Lisp recently and wanted to write a program which uses gtk interface. I've installed lambda-gtk bindings (on CMUCL). I want to have putpixel/getpixel ability on a pixbuf. But I found that I'm unable to direct access memory. (or just don't know how)

Function (gdk:pixbuf-get-pixels pixbuf) returns me a number - memory addr, I guess. In C++ I can easily get to the pixel I need. Is there any way to write my own putpixel in Lisp?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身狗的梦 2024-08-18 06:59:01

在 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)

In Lisp, modern and portable way to access C libraries and to do direct memory access is CFFI.

You can use it like this:

>(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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文