有没有一种快速、易于嵌入且非常适合高级游戏编程的脚本语言?
首先,我知道有很多与此相关的问题,但似乎没有一个问题对我的具体情况有帮助。特别是,lua 和 python 并没有像我希望的那样满足我的需求。可能不存在符合我的要求的语言,但在得出这个结论之前,很高兴听到更多的意见。 :)
正如您可能已经猜到的,我需要这样一种语言来用于我正在尝试创建的游戏引擎。该游戏引擎的目的是为用户提供构建游戏的基本工具,同时仍然让他们可以自由地创建许多不同类型的游戏。
因此,脚本语言应该能够直观地处理游戏概念。除此之外,应该很容易定义各种类型、使用稍微不同的属性对它们进行子类型化、动态查询和修改对象等等。
此外,游戏开发人员应该能够处理他们在脚本语言中遇到的每种情况。虽然渲染器和网络等基本组件将用 C++ 实现,但游戏特定的机制(例如绕行星旋转数百个对象)将用脚本语言处理。这意味着脚本语言必须非常快,1/10 C 速度可能是最低的。
然后就是调试的问题。有关发生错误的函数、堆栈跟踪和变量状态的信息应该是可访问的。
最后但并非最不重要的一点是,这是一个由一个人完成的项目。即使我愿意,我也没有足够的资源来花几周的时间来编写粘合代码。将语言与我的项目集成应该不会比集成 lua 困难多少。
检查两种建议的语言,lua 和 python,lua 速度快(luajit)且易于集成,但其标准调试工具似乎缺乏。更糟糕的是,lua 默认情况下根本没有类型系统。当然,您可以自己实现,但语法总是很奇怪且不直观。
另一方面,Python 使用起来非常舒适,并且有一个基本的类系统。然而,它并不是那么容易集成,它的范例并不真正涉及类型检查,而且对于更复杂的游戏来说它绝对不够快。我想再次指出,一切都将在 python 中完成。我很清楚,Python 对于 90% 的代码来说可能足够快。
还有 Scala,到目前为止我还没有看到建议。 Scala 似乎实际上满足了大部分要求,但是用 C 嵌入 Java VM 似乎并不是很容易,并且通常看起来 java 希望您围绕 java 构建应用程序,而不是相反。我也不确定 Scala 的函数范式是否有利于直观的游戏开发。
编辑:请注意,这个问题并不是要不惜一切代价寻找解决方案。如果没有比 lua 更好的语言,我会简单地妥协并使用它(实际上我已经将其链接到我的程序中)。我只是想确保在这样做之前我没有错过一些更合适的东西,因为 lua 对我来说远非完美的解决方案。
First off, I'm aware that there are many questions related to this, but none of them seemed to help my specific situation. In particular, lua and python don't fit my needs as well as I could hope. It may be that no language with my requirements exists, but before coming to that conclusion it'd be nice to hear a few more opinions. :)
As you may have guessed, I need such a language for a game engine I'm trying to create. The purpose of this game engine is to provide a user with the basic tools for building a game, while still giving her the freedom of creating many different types of games.
For this reason, the scripting language should be able to handle game concepts intuitively. Among other things, it should be easy to define a variety of types, sub-type them with slightly different properties, query and modify objects dynamically, and so on.
Furthermore, it should be possible for the game developer to handle every situation they come across in the scripting language. While basic components like the renderer and networking would be implemented in C++, game-specific mechanisms such as rotating a few hundred objects around a planet will be handled in the scripting language. This means that the scripting language has to be insanely fast, 1/10 C speed is probably the minimum.
Then there's the problem of debugging. Information about the function, stack trace and variable states that the error occurred in should be accessible.
Last but not least, this is a project done by a single person. Even if I wanted to, I simply don't have the resources to spend weeks on just the glue code. Integrating the language with my project shouldn't be much harder than integrating lua.
Examining the two suggested languages, lua and python, lua is fast(luajit) and easy to integrate, but its standard debugging facilities seem to be lacking. What's even worse, lua by default has no type-system at all. Of course you can implement that on your own, but the syntax will always be weird and unintuitive.
Python, on the other hand, is very comfortable to use and has a basic class system. However, it's not that easy to integrate, it's paradigm doesn't really involve type-checking and it's definitely not fast enough for more complex games. I'd again like to point out that everything would be done in python. I'm well aware that python would likely be fast enough for 90% of the code.
There's also Scala, which I haven't seen suggested so far. Scala seems to actually fulfill most of the requirements, but embedding the Java VM with C doesn't seem very easy, and it generally seems like java expects you to build your application around java rather than the other way around. I'm also not sure if Scala's functional paradigm would be good for intuitive game-development.
EDIT: Please note that this question isn't about finding a solution at any cost. If there isn't any language better than lua, I will simply compromise and use that(I actually already have the thing linked into my program). I just want to make sure I'm not missing something that'd be more suitable before doing so, seeing as lua is far from the perfect solution for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于似乎没有人比 lua/luajit 更了解组合,所以我想我就这样吧。感谢大家对此的意见。我个人认为 lua 作为游戏编程的高级语言非常缺乏,但它可能是最好的选择。因此,对于任何发现这个问题并且具有相同要求(快速、易于使用、易于嵌入)的人,您要么必须使用 lua/luajit,要么自己制作。 :)
Since noone seems to know a combination better than lua/luajit, I think I will leave it at that. Thanks for everyone's input on this. I personally find lua to be very lacking as a high-level language for game-programming, but it's probably the best choice out there. So to whomever finds this question and has the same requirements(fast, easy to use, easy to embed), you'll either have to use lua/luajit or make your own. :)
您可能会考虑mono。我只知道这种方法的一个成功案例,但它是一个很大的案例:带有单脚本的 C++ 引擎是 Unity< 中采用的方法/a>.
You might consider mono. I only know of one success story for this approach, but it is a big one: C++ engine with mono scripting is the approach taken in Unity.
尝试 Ring 编程语言
http://ring-lang.net
它是通用的多范式脚本语言,可以嵌入到 C/ C++ 项目,使用 C/C++ 代码扩展和/或用作独立语言。支持的编程范式包括命令式、过程式、面向对象、函数式、元编程、使用嵌套结构的声明式编程和自然编程。
语言简单、自然、鼓励组织并具有透明的实施。它具有紧凑的语法和一组功能,使程序员能够在很短的时间内创建自然的接口和声明性的特定于领域的语言。它非常小、速度快,并配有智能垃圾收集器,可将内存置于程序员的控制之下。它支持许多编程范例,附带有用且实用的库。该语言旨在提高生产力并开发可扩展的高质量解决方案。
编译器 + 虚拟机是 15,000 行 C 代码
在 C/C++ 程序中嵌入环形解释器
https://en.wikibooks.org/wiki/Ring/Lessons /Embedding_Ring_Interpreter_in_C/C%2B%2B_Programs
Try the Ring programming language
http://ring-lang.net
It's general-purpose multi-paradigm scripting language that can be embedded in C/C++ projects, extended using C/C++ code and/or used as standalone language. The supported programming paradigms are Imperative, Procedural, Object-Oriented, Functional, Meta programming, Declarative programming using nested structures, and Natural programming.
The language is simple, trying to be natural, encourage organization and comes with transparent implementation. It comes with compact syntax and a group of features that enable the programmer to create natural interfaces and declarative domain-specific languages in a fraction of time. It is very small, fast and comes with smart garbage collector that puts the memory under the programmer control. It supports many programming paradigms, comes with useful and practical libraries. The language is designed for productivity and developing high quality solutions that can scale.
The compiler + The Virtual Machine are 15,000 lines of C code
Embedding Ring Interpreter in C/C++ Programs
https://en.wikibooks.org/wiki/Ring/Lessons/Embedding_Ring_Interpreter_in_C/C%2B%2B_Programs
对于可嵌入性,您可以查看Tcl,或者如果您喜欢Scheme,请查看SIOD 或 狡猾。当然,我通常建议使用 Lua 或 Python,但你的问题排除了它们。
For embeddability, you might look into Tcl, or if you're into Scheme, check out SIOD or Guile. I would suggest Lua or Python in general, of course, but your question precludes them.