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!
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.
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.
I suspect that Tcl will have more libraries that you might find necessary or convenient along the way.
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.
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).
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.
© 2022 - 2024 — McMap. All rights reserved.