# What scripting language would you recommend for a C++ game project? [closed]

By scripting here I mean not just putting config data in a script, but scripting parts of the project like some class methods, test specific game loop, etc. This would be not just to accelerate development, but also allow players to see some of these scripts to tweak some aspects of the game.

Some language like Lua have some wrappers like luabind, but when I've used it in the past it had problems because it didn't support method redefinition in a context of inheritance.

What are your suggestions of language / wrappers to use or not to use?

I think Lua is the best shot.

LuaBind is great product but for me it looked too complicated. For one the code is not easy to follow where the classes and objects are. Also seeing that I wanted to integrate Lua into a wxWidgets application, using templates was a bit of a no no (you can read cross-platform issues on the wxWidgets site).

There are many other binding libraries:

What is the best C++/Lua wrapper?

Just select and enjoy.

• Yes, Lua is pretty simple and very easy to integrate with C. In fact, that's Lua's main objective, being an embedded language. Oct 22 '10 at 18:22
• Thanks for the reference on LuaBind, maybe digging into other binding libraries will convince me for taking Lua again Oct 23 '10 at 20:16
• I'd suggest only running your scripts in the main thread however, and provide a pool allocator for it if performance is a concern. Oct 26 '10 at 10:14

I would recommend Lua.
Python is very popular, too. Many featured game engines (Blender, for example) use it.
C++::Boost has a library to work with Python.

You can read this Game Engine overview. There is a Scripting column. You can see that Lua and Python are most popular scripting languages.

• About Boost, I think maybe it's a huge library and many many things are not quite useful in all projects. In fact luabind use Boost a lot and it's one of the things I didn't like. Oct 21 '10 at 1:24
• I would say it is an advantage. You have many many solutions out of the box. And your project has only 1 extern dependency - Boost. Not many many little libraries (that use different styles, approaches, licenses, and in turn may have extern implicit dependencies) that are hard to update, sync with your code and maintain. Oct 21 '10 at 2:28
• And you include only those Boost libraries (headers) that you need. Boost is huge, but you don't care until you need this or that. Oct 21 '10 at 2:33
• And about python and Lua, is there some wrappers for C++ that allow you to redefine class methods, create new methods, etc ? And is this feature can be controlled from the C++ code (for security) ? As I said, LuaBind does these things but fail in a context of inheritance, which is quite common in a game project. Methods I would like to redefined are for exemple, tests specific game loop, update methods of entities like player, update method of the game world itself, etc. Oct 21 '10 at 11:26
• Lua doesn't have classes and objects, but they can be emulated by tables. Here is a Lua library for OOP that I prefer: love2d.org/wiki/MiddleClass. Oct 21 '10 at 13:56

I've been liking Chaiscript; I haven't been using it for very long, but it seems pretty solid so far.

Unlike Python or lua, it's built from the ground up to be used with C++. The binding process seems a lot cleaner than with luabind/etc.

Here's the website's summary:

ChaiScript is the first and only scripting language designed from the ground up with C++ >compatibility in mind. It is an ECMAScript-inspired, embedded functional-like language.

• Interesting. What about performance tests? Is there any ChaiScript/Lua/Python comparison? Oct 21 '10 at 2:39
• Quite interesting, is there any disavantages / bugs / performance issus you've come through so far ? Oct 21 '10 at 11:27
• I haven't seen any benchmarks, but I haven't had any performance problems yet... my main grip so far would be that it doesn't convert between numeric types implicitly (so you get an error if you pass an int to a function taking a float, etc). Oct 21 '10 at 19:03
• Just an FYI, since this comment is 6 years old now - ChaiScript does do implicit numeric conversions now. Jun 3 '16 at 19:56

If you've got time, patience and the willingness to learn - you could always try developing your own scripting engine with all the features and syntax that you need.

1. You'll learn about an interesting part of Computer Science.
2. By developing an 'in-house' scripting engine, it gives you complete control from start to finish by allowing you to tailor the engine to exactly what you need.
3. If you need to make any changes later down the road, they can made somewhat easier knowing the in's and out's of your own codebase, rather than learning the in's and out's of someone elses.
4. You won't have to worry about keeping your engine up to date with someone else's patches.

1. Time. Not many people have it. If you need something NOW, try an already existing engine (like one of those already suggested).

2. Speed. A lot of existing scripting engines are very fast - a custom solution may not be as fast.

3. Team Size. A lot of existing scripting engines have larger teams of people working on the codebase, whether that be private teams or global volunteers, there is something to be said for code that is checked and re-checked by many other people.

4. A scripting engine requires a certain amount of initial planning to pull of effectively. There is a lot of groundwork that would need to be implemented as well that may not have to do with the actual scripting engine at all.

5. Your playerbase/developers would have to come accustomed to your scripting engine. This may not be a problem if the syntax and functionality is nearly the same as most modern scripting engines, but just be aware of that.

This is by no means an exhaustive list. If you find yourself having to make an large amount of changes to the back-end of an existing scripting language to get the functionality you want, IMO you should probably look for another engine that fits your requirements more closely or just build your own.

I realize people enjoy throwing around "laziness" and "don't re-invent the wheel" but I think there is something to be said about learning how this stuff is done. And a specific implementation is probably going to be better for your project than a generic implementation.

"Creating Scripting Systems in C++" seems to be the favored article(s) that people share when discussing the topic: http://www.gamedev.net/reference/list.asp?categoryid=76

• I agreed this have a particular educational advantage. Still it requires some knowledge and skills in programming languages theory (which a lot of people THINK they have) and some knowledge in theory of Computing. If this answers seams appealing to someone, I would suggest theses two books : amazon.com/gp/product/0136073476/ref=oss_product and amazon.com/gp/product/0534950973/ref=oss_product Oct 26 '10 at 11:35
• You'd be surprised how far you can go with no real knowledge of those things however. Lots of MUDs have a scripting language which is little more than a list of statements with some hacks to enable conditionals, and yet they can achieve a lot with that alone. Oct 26 '10 at 13:17
• Been there, done that. Learned a lot about parsing, compiler design, bytecode machines, all that stuff. Next time I'll probably use Lua and appreciate it all the more. :) Oct 27 '10 at 11:04

I've tried Lua, Python, Scheme, and Squirrel. Lua worked out the best; it has a larger community and better support than Squirrel, and much better memory and performance characteristics than Python. Scheme worked really well too, and has a really tiny interpreter, but it was hard for designers to wrap their heads around a functional language.

Here are links to luabind and tolua, wrappers for lua / c++

http://luabind.sourceforge.net/

http://www.tecgraf.puc-rio.br/~celes/tolua/