你如何将Lua粘合到C ++代码?

时间:2022-09-02 09:19:59

Do you use Luabind, toLua++, or some other library (if so, which one) or none at all?

您是使用Luabind,还是使用Lu ++,还是其他一些库(如果是,哪一个)或者根本没有?

For each approach, what are the pro's and con's?

对于每种方法,专业人士和骗子是什么?

4 个解决方案

#1


5  

I can't really agree with the 'roll your own' vote, binding basic types and static C functions to Lua is trivial, yes, but the picture changes the moment you start dealing with tables and metatables; things go trickier very quickly.

我真的不同意'滚动你自己'的投票,将基本类型和静态C函数绑定到Lua是微不足道的,是的,但是当你开始处理表格和元表时,图片就会改变;事情变得更加棘手。

LuaBind seems to do the job, but I have a philosophical issue with it. For me it seems like if your types are already complicated the fact that Luabind is heavily templated is not going to make your code any easier to follow, as a friend of mine said "you'll need Herb Shutter to figure out the compilation messages". Plus it depends on Boost, plus compilation times get a serious hit, etc.

LuaBind似乎做了这个工作,但我有一个哲学问题。对我而言,如果你的类型已经很复杂,那么Luabind非常模糊的事实并不会让你的代码变得更容易理解,因为我的一位朋友说“你需要Herb Shutter来找出编译信息” 。此外,它取决于Boost,加上编译时间受到严重打击等。

After trying a few bindings, Tolua++ seems the best. Tolua doesn't seem to be very much in development, where as Tolua++ seems to work fine (plus half the 'Tolua' tutorials out there are, in fact, 'Tolua++' tutorials, trust me on that:) Tolua does generate the right stuff, the source can be modified and it seems to deal with complicated cases (like templates, unions, nameless structs, etc, etc)

尝试几个绑定后,Tolua ++似乎是最好的。 Tolua似乎没有太多的开发,因为Tolua ++似乎工作正常(加上'Tolua'教程的一半,事实上,'Tolua ++'教程,相信我:) Tolua确实生成了正确的东西,源可以修改,它似乎处理复杂的情况(如模板,工会,无名结构等)

The biggest issue with Tolua++ seems to be the lack of proper tutorials, pre-set Visual Studio projects, or the fact that the command line is a bit tricky to follow (you path/files can't have white spaces -in Windows at least- and so on) Still, for me it is the winner.

Tolua ++最大的问题似乎是缺乏适当的教程,预先设置Visual Studio项目,或者命令行有点难以理解(你的路径/文件不能有空格 - 至少在Windows中) - 依此类推)对我而言,它仍然是胜利者。

#2


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.

Luabind:一旦你知道如何通过这种笨拙的模板语法绑定方法和类,它就非常简单易行,可以添加新的绑定。但是,luabind具有显着的性能影响,不应用于实时应用程序。比调用直接操作堆栈的C函数的开销大约多5-20倍。

#3


1  

I don't use any library. I have used SWIG to expose a C library some time ago, but there was too much overhead, and I stop using it.

我不使用任何库。我前段时间使用过SWIG来暴露一个C库,但开销太大了,我就停止使用了它。

The pros are better performance and more control, but its takes more time to write.

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

#4


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.

使用原始Lua API进行绑定 - 并保持简单。 Lua作者从API本身(AUX库)和库中获取灵感。

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.

通过一些实践,原始API是最佳选择 - 最大的灵活性和最少的不必要的开销。你已经得到了你想要的东西,而不是你需要它的方式。

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.

如果你必须绑定大型第三方库,使用自动生成器,如tolua,tolua ++(甚至可以针对特定情况自行编译)。它将使您免于手动工作。

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.

我不建议使用Luabind。目前它的发展停滞不前(但开始恢复生机),如果你遇到一些角落,你可能会独立。 Luabind也大量使用模板元编程。根据观点,这可能(也可能不)是不可接受的。

#1


5  

I can't really agree with the 'roll your own' vote, binding basic types and static C functions to Lua is trivial, yes, but the picture changes the moment you start dealing with tables and metatables; things go trickier very quickly.

我真的不同意'滚动你自己'的投票,将基本类型和静态C函数绑定到Lua是微不足道的,是的,但是当你开始处理表格和元表时,图片就会改变;事情变得更加棘手。

LuaBind seems to do the job, but I have a philosophical issue with it. For me it seems like if your types are already complicated the fact that Luabind is heavily templated is not going to make your code any easier to follow, as a friend of mine said "you'll need Herb Shutter to figure out the compilation messages". Plus it depends on Boost, plus compilation times get a serious hit, etc.

LuaBind似乎做了这个工作,但我有一个哲学问题。对我而言,如果你的类型已经很复杂,那么Luabind非常模糊的事实并不会让你的代码变得更容易理解,因为我的一位朋友说“你需要Herb Shutter来找出编译信息” 。此外,它取决于Boost,加上编译时间受到严重打击等。

After trying a few bindings, Tolua++ seems the best. Tolua doesn't seem to be very much in development, where as Tolua++ seems to work fine (plus half the 'Tolua' tutorials out there are, in fact, 'Tolua++' tutorials, trust me on that:) Tolua does generate the right stuff, the source can be modified and it seems to deal with complicated cases (like templates, unions, nameless structs, etc, etc)

尝试几个绑定后,Tolua ++似乎是最好的。 Tolua似乎没有太多的开发,因为Tolua ++似乎工作正常(加上'Tolua'教程的一半,事实上,'Tolua ++'教程,相信我:) Tolua确实生成了正确的东西,源可以修改,它似乎处理复杂的情况(如模板,工会,无名结构等)

The biggest issue with Tolua++ seems to be the lack of proper tutorials, pre-set Visual Studio projects, or the fact that the command line is a bit tricky to follow (you path/files can't have white spaces -in Windows at least- and so on) Still, for me it is the winner.

Tolua ++最大的问题似乎是缺乏适当的教程,预先设置Visual Studio项目,或者命令行有点难以理解(你的路径/文件不能有空格 - 至少在Windows中) - 依此类推)对我而言,它仍然是胜利者。

#2


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.

Luabind:一旦你知道如何通过这种笨拙的模板语法绑定方法和类,它就非常简单易行,可以添加新的绑定。但是,luabind具有显着的性能影响,不应用于实时应用程序。比调用直接操作堆栈的C函数的开销大约多5-20倍。

#3


1  

I don't use any library. I have used SWIG to expose a C library some time ago, but there was too much overhead, and I stop using it.

我不使用任何库。我前段时间使用过SWIG来暴露一个C库,但开销太大了,我就停止使用了它。

The pros are better performance and more control, but its takes more time to write.

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

#4


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.

使用原始Lua API进行绑定 - 并保持简单。 Lua作者从API本身(AUX库)和库中获取灵感。

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.

通过一些实践,原始API是最佳选择 - 最大的灵活性和最少的不必要的开销。你已经得到了你想要的东西,而不是你需要它的方式。

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.

如果你必须绑定大型第三方库,使用自动生成器,如tolua,tolua ++(甚至可以针对特定情况自行编译)。它将使您免于手动工作。

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.

我不建议使用Luabind。目前它的发展停滞不前(但开始恢复生机),如果你遇到一些角落,你可能会独立。 Luabind也大量使用模板元编程。根据观点,这可能(也可能不)是不可接受的。