Question

In common lisp, is there a recommended naming convention for foreign types? (and types in general)? For example:

(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))

In this example defcstruct Point corresponds to C/C++ type struct Point{int32 x, y;};, glyph-index-t corresponds to typedef uint32 GlyphIndex; and font-ptr-t is struct Font*.

I'm unsure whether I should simply add -t suffix to everything (as I did with glyph-index-t), make the interpreter case-sensitive (so I could use Uppercase to indicate types, like in C++, which is probably a bad idea), or whether there is some other traditional way to do it. Any advice?

Was it helpful?

Solution 2

After some testing, I found out that cffi typenames don't collide with CLOS classes and defstructs. So distinct type name is not necessary.

Regarding "standard for type names" in general, lisp has separate "namespaces" for functions and types. (to be precise, same symbol can be used as function name and as a type name, as far as I can tell).

Conclusion: It looks like distinct naming scheme for cffi types is unnecessary.

OTHER TIPS

CFFI has a number of functions relating to the translation of names. That linked documentation includes:

It probably make sense to try to use names that interact well with these functions. For instance, there's an example on the translate-name-from-foreign page (which I realize is about function naming, not type naming, though):

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

I'd also suggest finding some libraries that use CFFI to generate bindings, and looking at what they do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top