Can I extend lisp with c++?

天涯浪子 提交于 2019-11-30 15:45:36

问题


Can I call a function from lisp from a library written in c or c++? How can I extend lisp? This is useful when you want to do some system calls or stuff like that.


回答1:


It is unusual to call non-lisp code from lisp, and rarely necessary. CLX (the X11 client implementation for CL) doesn't link to the Xlib implementation but "speaks" X11 directly. On any system, your CL implementation is likely to already have excellent operating system hooks rendering this unnecessary.

That said, the answer depends on the lisp implementation:

In ECL you can actually host a CL environment under C and simply call cl_eval() with the code to execute. This can let you write your application (or application host) in C (or C++) and "call to" lisp code.

In CCL, there is a C-compatible calling interface which lets you do something like this:

(with-cstrs ((x "Hello World"))
  (#_puts x))

In most other CL implementations (like SBCL; and yes this works in ECL and CCL as well) you can use UFFI (or CFFI) which simply lets you call C functions, which is what other people are talking about. If this is all you want to do, then CFFI is a good, safe place to start.




回答2:


See UFFI and CFFI and the slicker Clozure FFI




回答3:


CFFI!



来源:https://stackoverflow.com/questions/379136/can-i-extend-lisp-with-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!