我可以用c ++扩展lisp吗? [英] Can I extend lisp with c++?

查看:214
本文介绍了我可以用c ++扩展lisp吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从用c或c ++编写的库调用lisp中的函数吗?如何扩展lisp?
当你想做一些系统调用或类似的东西时,这是非常有用的。

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.

推荐答案

来自lisp的非lisp代码,很少需要。 CLX(CL的X11客户端实现)不链接到Xlib实现,而是直接说X11。在任何系统上,你的CL实现很可能已经有优秀的操作系统钩子使这不必要。

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.

这就是说,答案取决于lisp实现:

That said, the answer depends on the lisp implementation:

ECL 中,您实际上可以在C下托管CL环境,只需调用 cl_eval()与要执行的代码。这可以让你用C(或C ++)编写你的应用程序(或应用程序主机)和调用lisp代码。

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.

CCL ,有一个C兼容的调用界面,可以让你这样做:

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

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

在大多数其他CL实现(如SBCL;是的,这也适用于ECL和CCL),你可以使用UFFI(或CFFI),它只是让你调用C函数,这是什么其他人们在谈论。如果这是所有你想做的,那么CFFI是一个好的,安全的起点。

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.

这篇关于我可以用c ++扩展lisp吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆