views:

1126

answers:

5

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!

+9  A: 

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.

RHSeeger
+5  A: 

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.

RBerteig
+6  A: 

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

George Jempty
+9  A: 

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.

Kylotan
I find it amusing that we can have such opposite opinions. Everything you say makes Lua better than Tcl is something I'd say makes Tcl better than Lua. The Tcl syntax to me is considerably cleaner and more obvious than Lua's, etc.
RHSeeger
I'll agree with RHSeeger on the comment that "what you say about Lua I would say about Tcl". You (kylotan) said you thought Lua was better for less experienced users but I also think that is backwards. The main problem with Tcl IMO is that experienced programmers carry too much baggage -- expectations about how a language should work. Tcl is unconventional due to its simplicity, but that simplicity is its strength. Everything you need to know about Tcl can be expressed on a single web page.
Bryan Oakley
This is on the verge of devolving into "language wars". I think its a matter of the right tool for the job, and, syntax aside, both tools in this case are nearly equally suited, but in my opinion Tcl wins because of its maturity and therefore it's libraries; indeed Lua seems notoriously week in this department. As for syntax, yes Lua's might seem more familiar, almost Basic/Python-esque, and that indeed could be a strength. But for those who have only scratched the surface of Tcl, I urge you: scratch deeper. When you "get it" it's practically at the same level as "getting" Lisp or Haskell.
George Jempty
I did admit and state that my opinion was subjective, and that TCL is perfectly good for someone who knows it. However, in the domain of games scripting, typically the type of person who will be doing it will be more familiar with the simple mainstream imperative languages like VBScript and Javascript, and will be a far way from advanced programmers who can get the best out of Haskell or Lisp. This is just what I've seen in the field and is largely unrelated to how powerful TCL is as a language.
Kylotan
Oh, and on the library point - often for game scripting you explicitly do not want to expose any external libraries to the script, for performance, maintenance, or security reasons. Again it all depends on who will be writing the scripts, and hopefully this is something the original poster will consider.
Kylotan
On the client side, no, you wouldn't want much library support, but on the server, where all the coders/users are trusted, then it's at worst harmless, and possibly very useful.
TokenMacGuy
Even server side it can be risky, since the users are not necessarily software engineers but often less technical designers. These users can't always be expected to be aware of the full implications of certain system calls, etc. Therefore you often have them work through only the sandboxed interface that you provide for them. Obviously the truth of this in the OP's case will depend on his particular situation, but generally speaking an embedded scripting language in a game is there for syntax, not for libraries.
Kylotan
@Kylotan Lua has if anything more complex syntax than TCL, this seems to be a common misunderstanding of TCL, people reading more into it than is really there. that said you still may be right that Lua is more newb friendly as TCLs simple syntax appears to be to simple for many to really grok
jk
@jk: I definitely understand what you mean, in that TCL has a elegantly small number of rules that dictate how it operates. But it relies on well-formed punctuation and formatting rather than English language keywords which alone makes it less friendly for the (English-speaking!) beginner. IMHO.
Kylotan
+4  A: 

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).

TokenMacGuy
I didn't think about Javascript. That is a possible idea....
Byron Whitlock
Javascript might have the advantage of being familiar to casual coders, but definately has the disadvantage of sparse runtime libraries, at least for the C implementations.
TokenMacGuy