这是一个 C 语言的函数:
union Example {
int number;
void *pointer;
};
void return_a_value (union Example *ptr) {
(*ptr).number = 1;
}
现在我想通过CFFI在Common Lisp中调用它,怎么办?
(defcunion Example
(number :int)
(ptr :pointer))
(defcfun "return_a_value" :void
(retval :pointer)) ; I'm not very sure here..
最佳答案
到目前为止一切正常,包括您对
返回值
。这就是您调用该函数的方式:
(with-foreign-object (arg 'example)
(setf (foreign-slot-value arg 'example 'number) 123)
(return-a-value arg)
(foreign-slot-value arg 'example 'number))
关于lisp - 通过 CFFI 传递获取结果的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14979656/