2

如何从调用返回字符串常量ffi:c-inline

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

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

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

未知的表示类型:STRING

4

1 回答 1

5

使用:cstring代替:string

常量.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

于 2017-11-30T00:07:09.680 回答