如何在ecl中调用ffi:c-inline中的字符串?

时间:2017-11-29 21:50:47

标签: c common-lisp ecl

如何从调用ffi:c-inline

返回字符串常量

我尝试了以下变体而没有成功(ORGANIZATION是constants.h中定义的常量):

(ffi:clines "#include \"./constants.h\"")
(ffi:c-inline () () :string "ORGANIZATION" :one-liner t)

上面的示例导致以下编译器错误:

  

未知的代表类型:STRING

1 个答案:

答案 0 :(得分:5)

使用:cstring代替:string

constants.h:

#define ORGANIZATION "foobar"

ecl.lsp:

(ffi:clines "#include \"./constants.h\"")
(defun myfun ()
  (ffi:c-inline () () :cstring "ORGANIZATION" :one-liner t))

来自ecl提示:

> (compile-file "ecl.lsp" :load t)
...
> (myfun)

"foobar"
> 

参考:https://common-lisp.net/project/ecl/static/ecldoc/Extensions.html#Primitive-Types