gpt4 book ai didi

common-lisp - cffi/外来类型的推荐命名约定

转载 作者:行者123 更新时间:2023-12-02 00:07:55 25 4
gpt4 key购买 nike

在普通的 lisp 中,是否有推荐的外来类型的命名约定? (和一般类型)?例如:

(cffi:defctype glyph-index-t :uint32)
(cffi:defcstruct Point
(x :int32)
(y :int32))

(cffi:define-foreign-library fontlib (t (:default "font")))
(cffi:use-foreign-library fontlib)

(cffi:defctype font-ptr-t :pointer)
(cffi:defcfun "hasKerning" :boolean (fontptr font-ptr-t))
(cffi:defcfun "getKerning" Point
(fontptr font-ptr-t)
(glyph1 glyph-index-t)
(glyph2 glyph-index-t))

本例中defcstruct Point对应C/C++类型struct Point{int32 x, y;};, glyph-index-t 对应于 typedef uint32 GlyphIndex;font-ptr-tstruct Font*

我不确定我是否应该简单地为所有内容添加 -t 后缀(就像我对 glyph-index-t 所做的那样),使解释器区分大小写(所以我可以使用 Uppercase 来指示类型,就像在 C++ 中一样,这可能是个坏主意),或者是否有其他传统方法可以做到这一点。有什么建议吗?

最佳答案

CFFI 有一个 number of functions与名字的翻译有关。该链接文档包括:

尝试使用与这些函数交互良好的名称可能是有意义的。例如,translate-name-from-foreign 页面上有一个示例(不过我意识到这是关于函数命名,而不是类型命名):

CFFI> (defcfun "someXmlFunction" ...)
=> SOME-XML-FUNCTION

我还建议找到一些使用 CFFI 生成绑定(bind)的库,并查看它们的作用。

关于common-lisp - cffi/外来类型的推荐命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17212062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com