Common Lisp的,CFFI,和实例C结构 [英] Common lisp, CFFI, and instantiating c structs

查看:448
本文介绍了Common Lisp的,CFFI,和实例C结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在谷歌一下,哦,寻找一个解决方案,以这3小时的问题。我试图找出如何使用LISP实例CFFI C结构。我有在C结构:

I've been on google for about, oh, 3 hours looking for a solution to this "problem." I'm trying to figure out how to instantiate a C structure in lisp using CFFI. I have a struct in c:

struct cpVect{cpFloat x,y;}

简单吧?我有自动生成CFFI绑定(痛饮,我认为)这个结构:

Simple right? I have auto-generated CFFI bindings (swig, I think) to this struct:

(cffi:defcstruct #.(chipmunk-lispify "cpVect" 'classname)
    (#.(chipmunk-lispify "x" 'slotname) :double)
    (#.(chipmunk-lispify "y" 'slotname) :double))

这会产生一个结构VECT与插槽:X和:Y,其中外商槽的名字证实(请注意,我既不产生的绑定或编程的C库(花栗鼠物理),但实际功能是从口齿不清就好)调用。

This generates a struct "VECT" with slots :X and :Y, which foreign-slot-names confirms (please note that I neither generated the bindings or programmed the C library (chipmunk physics), but the actual functions are being called from lisp just fine).

我搜索远播,也许我已经看到了100倍,轻轻带过,但我无法弄清楚如何在LISP等功能,使用创建cpVect的实例。

I've searched far and wide, and maybe I've seen it 100 times and glossed over it, but I cannot figure out how to create a instance of cpVect in lisp to use in other functions.

请注意功能:

cpShape *cpPolyShapeNew(cpBody *body, int numVerts, cpVect *verts, cpVect offset)

不仅需要一个cpVect,还指向了一套cpVects,这引出了我的第二个问题:我怎么创建一个指向一组结构的

Takes not only a cpVect, but also a pointer to a set of cpVects, which brings me to my second question: how do I create a pointer to a set of structs?

我去过 http://common-lisp.net /project/cffi/manual/html_node/defcstruct.html 并尝试了code,却得到错误:未绑定变​​量:PTR(我在Clozure CL),更何况,看起来只返回一个指针,而不是一个实例

I've been to http://common-lisp.net/project/cffi/manual/html_node/defcstruct.html and tried the code, but get "Error: Unbound variable: PTR" (I'm in Clozure CL), not to mention that looks to only return a pointer, not an instance.

我是新来口齿不清,已经持续pretty强,到目前为止,但是这是第一个真正的问题,我已经打了,我想不通。谢谢!

I'm new to lisp, been going pretty strong so far, but this is the first real problem I've hit that I can't figure out. Thanks!

推荐答案

大多数的Common Lisp实现不允许传递堆栈结构。有一个 fsbv库,使用libffi补充说,能力。如果您知道的结构布局可以手动分解它作为一系列的基本论点,但是这显然是易碎的。

Most Common Lisp implementations do not allow passing structures on stack. There is a fsbv library which uses libffi to add that capability. If you know the structure layout you can decompose it manually as a series of basic arguments, but that is obviously brittle.

这篇关于Common Lisp的,CFFI,和实例C结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆