TCL 与 Lua - 编写 MMO 服务器脚本

发布于 2024-08-03 23:46:32 字数 159 浏览 3 评论 0原文

我有一个 C++ 服务器端项目,需要将某种脚本嵌入其中。它是在线 MMO 类型服务器的一部分。我在使用 TCL 方面拥有丰富的经验,这似乎是天作之合。我在游戏开发期间使用过少量的 Lua,我想知道这是否是一种更好的嵌入式脚本语言。学习一门新语言也很好。 TCL 与 Lua 相比有何相对优势和劣势?谢谢!

I have a c++ server side project that I need to embed some sort of scripting into. It is part of an online MMO type of server. I have significant experience using TCL, and it seems like the natural fit. I've done a minimal amount of Lua in my game dev days, and I wonder if this might be a better language for embedded scripting. It is also nice to learn a new language. What are the relative strengths and weaknesses of TCL vs Lua? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

樱桃奶球 2024-08-10 23:46:32

老实说,他们都非常适合这项任务。两者都很容易嵌入到应用程序中,并且语法相当简单。我知道在 Tcl 中添加新命令(与应用程序交互)非常简单,而且我听说 Lua 也非常擅长此类事情。

我的建议是尝试使用 Lua 一段时间,看看您是否喜欢它(因为您已经了解 Tcl)...然后选择您感觉最舒服的一个。如果您编写了大量代码,那么您最终会经常使用它,因此您也需要一些可以使用的东西。最后,这两种语言选择对于最终用户来说都应该相当容易编写脚本。

我个人更喜欢 Tcl,因为我不喜欢 Lua(我已经为《魔兽争霸》插件编写了相当多的编程),并且因为我喜欢 Tcl(我已经用它完成了大量的专业和私人工作编程)。

编辑:添加了关于两者对最终用户来说都很容易的注释。得到了 2 票反对票,除了没有澄清我声明中的原因部分之外,想不出其他可能的原因。

Honestly, they're both extremely well suited to the task. Both are easy to embed in an application and have a fairly simple syntax. I know for a fact that it's extremely simple to add new commands (to interact with the application) in Tcl, and I'm told Lua is very good at this type of thing, too.

My recommendation would be to play around with Lua for a while to see how you like it (since you already know Tcl)... and then pick the one that feels most comfortable to you. If you're writing much of the code, you'll wind up working with it a lot, so you'll need something you can use, too. In the end, both language choices should be fairly easy for your end users to script in.

My personal preference is Tcl, both because I don't like Lua (I've done a reasonable amount of programming in it for Warcraft addsons) and because I love Tcl (I've done a LOT of programming in it for both professional and private work).

Edit: Added the note about both being easy for end users. Got 2 down votes and couldn't think of anything else that it might be for other than not clarifying the why part of my statement.

南汐寒笙箫 2024-08-10 23:46:32

我想我和 RHSeeger 正好相反。我已经在游戏中使用了 Lua 和 TCL(顺便说一下,在线游戏),如果可以选择的话,我不会再用 10 英尺的转杆碰 TCL。我非常主观的观点是 Lua 是一种理智的语言,而 TCL 不是。相对于其他脚本语言选项,TCL 语法对大多数人来说非常晦涩,有所有的 set、expr、美元符号和大量括号等。它唯一的客观好处是易于嵌入 - 但 Lua 也毫不逊色。那个部门也可以。

如果这个脚本接口纯粹适合您,那么您不妨选择 TCL,因为 Lua 不会为您提供任何新功能(除非您喜欢面向对象)。在熟练用户手中,TCL 是一个合理的工具。然而,如果您希望经验较少的用户使用该系统,那么请选择 Lua - 更简单的语法将为他们带来很大的生产力。

I guess I'm the opposite of RHSeeger there. I've used both Lua and TCL embedded in games (online games, incidentally) and I wouldn't touch TCL again with a 10' bargepole if I had the choice. My very subjective opinion is that Lua is a sane language and TCL isn't. Relative to the other options for scripting languages, TCL syntax is very obscure to most people, with all the set and expr and dollar signs and lots of brackets etc. The only objective benefit it has is ease of embedding - but Lua is no slouch in that department either.

If this scripting interface is purely for you then you may as well go with TCL because Lua won't offer you anything new (unless object orientation is your thing). In the hands of a skilled user TCL is a reasonable tool. If, however, you expect less experienced users to use the system then go with Lua - the simpler syntax will buy them a lot of productivity.

眸中客 2024-08-10 23:46:32

我怀疑 Tcl 将拥有更多您可能会发现必要或方便的库。

I suspect that Tcl will have more libraries that you might find necessary or convenient along the way.

雅心素梦 2024-08-10 23:46:32

Lua C API 非常容易集成到应用程序中。从 C 语言中,您可以完全访问 Lua 状态及其本机数据类型。例如,我建议使用 Lua 来实现哈希表,即使不需要编写脚本。

用 C 编写的 Lua 函数可以作为全局名称注入,像大多数标准库函数一样收集在表中,或者在 DLL 中实现并在运行时动态加载。这使得应用程序能够提供稳定的 API,并支持用 Lua 或 C 编写的插件。Lua

作为一种语言非常强大,支持函数式和面向对象的编程风格。它的重量也令人惊讶:完整的源代码包和完整的文档大小远低于 1 MB,而 DLL 中的整个 VM、编译器和标准库在 Windows 上仅为 164 KB。

从版本 2 左右开始,我就没有认真研究过 TCL...我不会尝试以具体的方式比较它们。我相信它们都是为了适应相同的利基市场而发明的,而且几乎是在同一时间发明的。它们当然都是成熟的语言,拥有狂热的用户社区。

The Lua C API is extremely easy to integrate into an application. From C you have complete access to the Lua state, and to its native data types. I've recommended using Lua just to get the hash table implementation even with no need for scripting, for instance.

Lua functions written in C can be injected as global names, collected in a table like most of the standard library functions, or implemented in DLLs and dynamically loaded at runtime. That permits the application to provide a stable API, as well as to support plugins written in either Lua or C.

Lua as a language is surprisingly powerful, with support for both functional and object oriented programming styles. It is also surprisingly lightweight: the complete source kit and full documentation fits in well under 1 MB, and the whole VM, compiler, and standard libraries in a DLL is only 164KB on Windows.

I haven't seriously examined TCL since version 2 or so... I won't try to compare them in a concrete way. I believe that they both were invented to fit the same niche, and at about the same time. They certainly are both mature languages with avid user communities.

陈年往事 2024-08-10 23:46:32

正如其他人所说,两种语言都可以很好地工作。第三种选择也可能有效,那就是 JavaScript,因为它适合同样的利基市场。我不会试图吸引您使用其中一种语言(因为我非常喜欢两种语言),我会尝试关注一些客观差异,并指出我认为其中一种语言领先于另一种语言的地方。

游戏服务器中最重要的问题可能是原始性能。这两种语言都很成熟并且经过了良好的优化,但都认识到某些问题最好通过推迟编译代码来优化。两种语言基本上使用相同的机制来执行此操作。从语言本身的角度来看,Lua 看起来只是更快一点。 link

从图书馆的角度来看,这是下一个重要因素,两者都不是语言需要使用任何库才能有用;也就是说,与 Java 等需要大型运行时库才能发挥作用的语言相比,这两种语言都非常紧凑;同样,这是他们原始设计要求的结果。两种语言都有丰富的附加库可供选择,但至少在我的印象中,TCL 在这一类别中的种类更多一些。 tcl:( Tcl 扩展存档 / Tcl 扩展存储库 ) lua: ( LuaForge

另一个区别是核心语言本身之间的区别。两种语言都重视简单性而不是风格,但这就是相似之处。 Lua 使用大多数程序员可能熟悉的语法,具有非常简单的上下文无关语法。 TCL 语法也很简单,但与其他现有语言没有任何共同点,尽管它表面上看起来有点像 unix shell 语言。 Tcl 可能只对非程序员来说更容易,因为它的面向行的命令语法非常清晰,但有其他语言经验的程序员通常反对它晦涩难懂的语法。两者在代码生成方面都不是非常宽容,但两者都具有强大的元编程工具(可比,但可能不如 CLISP 宏强大)。

As others have stated, both languages would work very well. A third option that would also likely work about as well is JavaScript, since it fits in about the same the same niche. Instead of trying to Woo you to one or the other (As I like both languages very much) I'll try to focus on some of the objective differences, and point out where I think one is ahead of the other.

The most important issue in a game server is likely to be raw performance. Both languages are mature and well optimized, but both also recognize that some issues are best optimized by deferring to compiled code. Both languages use basically the same mechanism for performing this. From the point of view of the languages themselves, It looks like Lua is just a bit faster. link

From the point of view of Libraries, which is the next big factor, Neither language requires the use of any libraries to be useful; that is both languages are very compact, as compared to languages such as Java which require large runtime libraries to be useful; Again, this is a consequence of their original designs requirements. Both languages have plentiful add-on libraries to choose from, But It's my impression at least that TCL has somewhat more variety in this category. tcl:( Tcl Extension Archive / Tcl Extension Repository ) lua: ( LuaForge )

Another difference is between the core languages themselves. Both languages value simplicity over style, but that's where the similarity ends. Lua uses what might be familiar syntax to most programmers, with a very simple context free grammar. TCL syntax is also simple, but doesn't really have anything in common with other existing languages, although it looks superficially a bit like unix shell language. Tcl is probably only easier on non-programmers because its line oriented command syntax is pretty clear, but programmers experienced in other languages usually object to its arcane syntax. Neither one is terribly forgiving in terms of code generation, but both have strong metaprogramming facilities (comparable, but perhaps not as robust as CLISP macros).

比忠 2024-08-10 23:46:32

Lua 有 LuaJIT,它是一个 JIT 编译器,可以在紧密循环上达到 C 速度,用于 Snabb Switch,其中性能至关重要(Snabb 每秒可以处理千兆位,全部通过 LuaJIT 处理)。 LuaJIT 还有一个易于使用的 FFI,它允许人们无需编写 C 存根代码即可访问 C 函数。

PUC-Lua(标准实现)支持内存不足的恢复。 LuaJIT 和 TCL 都没有。

Lua has LuaJIT, which is a JIT compiler that reaches C speeds on tight loops and is used for projects like Snabb Switch, where performance is critical (Snabb can handle gigabits per second, all processed through LuaJIT). LuaJIT also has an easy-to-use FFI which allows one to access C functions without writing C stub code.

PUC-Lua (the standard implementation) supports recovering from running out of memory. Neither LuaJIT nor TCL do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文