12

你是使用 Luabind、toLua++ 还是其他一些库(如果是,是哪一个),还是根本不使用?

对于每种方法,优点和缺点是什么?

4

4 回答 4

5

我真的不能同意“自己动手”的投票,将基本类型和静态 C 函数绑定到 Lua 是微不足道的,是的,但是当您开始处理表和元表时,情况就会发生变化;事情变得非常棘手。

LuaBind 似乎可以完成这项工作,但我有一个哲学问题。对我来说,如果你的类型已经很复杂,那么 Luabind 被大量模板化的事实不会让你的代码更容易理解,正如我的一个朋友所说“你需要 Herb Shutter 来找出编译消息” . 另外,它依赖于 Boost,加上编译时间会受到严重影响,等等。

在尝试了一些绑定之后,Tolua++ 似乎是最好的。Tolua 似乎没有进行太多开发,因为 Tolua++ 似乎工作正常(加上一半的“Tolua”教程实际上是“Tolua++”教程,相信我:) Tolua 确实生成了正确的东西,可以修改源代码,它似乎可以处理复杂的情况(如模板、联合、无名结构等)

Tolua++ 的最大问题似乎是缺乏适当的教程、预设的 Visual Studio 项目,或者命令行有点难以理解(你的路径/文件不能有空格 - 至少在 Windows 中) - 等等)不过,对我来说,它是赢家。

于 2008-12-10T21:25:48.517 回答
4

To answer my own question in part:

Luabind: once you know how to bind methods and classes via this awkward template syntax, it's pretty straightforward and easy to add new bindings. However, luabind has a significant performance impact and shouldn't be used for realtime applications. About 5-20 times more overhead than calling C functions that manipulate the stack directly.

于 2008-09-19T16:19:05.593 回答
1

我不使用任何图书馆。前段时间我使用 SWIG 公开了一个 C 库,但是开销太大,我停止使用它。

优点是更好的性能和更多的控制,但它需要更多的时间来编写。

于 2008-09-30T23:21:14.960 回答
1

Use raw Lua API for your bindings -- and keep them simple. Take inspiration in the API itself (AUX library) and libraries by Lua authors.

With some practice raw API is the best option -- maximum flexibility and minimum of unneeded overhead. You've got what you want and no more, the way you need it to be.

If you must bind large third-party libraries use automated generators like tolua, tolua++ (or even roll your own for the specific case). It would free you from manual work.

I would not recommend using Luabind. At the moment it's development stalled (however starting to come back to life), and if you would meet some corner case, you may be on your own. Also Luabind heavily uses template metaprogramming. This may (and may not) be unacceptable, depending on the point of view.

于 2008-10-04T17:21:25.073 回答