常见的 lisp sbcl 手册 ffi 示例失败
common lisp sbcl manual ffi example failed
我阅读了 sbcl manual,但在 8.5 外国数据结构示例章节中遇到了问题。
我用下面的例子来验证是否可以运行正确。
_______________________________________________________________
或者考虑这个外部 C 变量和一些访问的例子:
struct c_struct {
short x, y;
char a, b;
int z;
c_struct *n;
};
extern struct c_struct *my_struct;
my_struct->x++;
my_struct->a = 5;
my_struct = my_struct->n;
在 Lisp 中可以这样操作:
(define-alien-type nil
(struct c-struct
(x short)
(y short)
(a char)
(b char)
(z int)
(n (* c-struct))))
(define-alien-variable "my_struct" (* c-struct))
(incf (slot my-struct 'x))
(setf (slot my-struct 'a) 5)
(setq my-struct (slot my-struct 'n))
________________________________________________________________
现在我 运行 上面的示例代码是关于粘液的,它发出错误信号。
unknown alien type: C-STRUCT
[Condition of type SIMPLE-ERROR]
Restarts:
0: [RETRY] Retry SLIME REPL evaluation request.
1: [ABORT] Return to sldb level 7.
2: [RETRY] Retry SLIME REPL evaluation request.
3: [ABORT] Return to sldb level 6.
4: [RETRY] Retry SLIME REPL evaluation request.
5: [ABORT] Return to sldb level 5.***
我应该怎么做才能定义这样一个可以包含它自己的点的结构。
请注意手册还说:
Types may be either named or anonymous. With structure and union types, the name is part of the type specifier, allowing recursively defined types such as:
(struct foo (a (* (struct foo))))
我没有使用过 SBCL 的 FFI,但我猜这意味着您应该使用:
(define-alien-variable "my_struct" (* (struct c-struct)))
我阅读了 sbcl manual,但在 8.5 外国数据结构示例章节中遇到了问题。
我用下面的例子来验证是否可以运行正确。
_______________________________________________________________
或者考虑这个外部 C 变量和一些访问的例子:
struct c_struct {
short x, y;
char a, b;
int z;
c_struct *n;
};
extern struct c_struct *my_struct;
my_struct->x++;
my_struct->a = 5;
my_struct = my_struct->n;
在 Lisp 中可以这样操作:
(define-alien-type nil
(struct c-struct
(x short)
(y short)
(a char)
(b char)
(z int)
(n (* c-struct))))
(define-alien-variable "my_struct" (* c-struct))
(incf (slot my-struct 'x))
(setf (slot my-struct 'a) 5)
(setq my-struct (slot my-struct 'n))
________________________________________________________________
现在我 运行 上面的示例代码是关于粘液的,它发出错误信号。
unknown alien type: C-STRUCT
[Condition of type SIMPLE-ERROR]
Restarts:
0: [RETRY] Retry SLIME REPL evaluation request.
1: [ABORT] Return to sldb level 7.
2: [RETRY] Retry SLIME REPL evaluation request.
3: [ABORT] Return to sldb level 6.
4: [RETRY] Retry SLIME REPL evaluation request.
5: [ABORT] Return to sldb level 5.***
我应该怎么做才能定义这样一个可以包含它自己的点的结构。
请注意手册还说:
Types may be either named or anonymous. With structure and union types, the name is part of the type specifier, allowing recursively defined types such as:
(struct foo (a (* (struct foo))))
我没有使用过 SBCL 的 FFI,但我猜这意味着您应该使用:
(define-alien-variable "my_struct" (* (struct c-struct)))