Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

closed as off-topic by Josh Petrie May 14 at 2:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

7 Answers 7

up vote 9 down vote accepted

Lua-scripted video games
Lua-scriptable game engines

I think Lua is the best shot.

This article is about integrating Lua and C++. It says:

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:

http://luabridge.sourceforge.net/
http://www.stackedboxes.org/~lmb/diluculum/
http://cpplua.sourceforge.net/
http://www.tecgraf.puc-rio.br/~celes/tolua/

What is the best C++/Lua wrapper?

Just select and enjoy.

share|improve this answer
    
Yes, Lua is pretty simple and very easy to integrate with C. In fact, that's Lua's main objective, being an embedded language. –  Marco Mustapic 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 –  Frédérick Imbeault 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. –  Kylotan Oct 26 '10 at 10:14
add comment

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.

ChaiScript is licensed under the BSD license.

share|improve this answer
    
Interesting. What about performance tests? Is there any ChaiScript/Lua/Python comparison? –  topright Oct 21 '10 at 2:39
    
Quite interesting, is there any disavantages / bugs / performance issus you've come through so far ? –  Frédérick Imbeault 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). –  Riley Adams Oct 21 '10 at 19:03
add comment

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.
I've read about Squirell, but didn't use it.

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

share|improve this answer
    
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. –  Frédérick Imbeault Oct 21 '10 at 1:24
1  
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. –  topright Oct 21 '10 at 2:28
1  
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. –  topright 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. –  Frédérick Imbeault 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. –  topright Oct 21 '10 at 13:56
show 3 more comments

Why not build your own?

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.

Advantages

  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.

Disadvantages

  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

share|improve this answer
2  
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 –  Frédérick Imbeault 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. –  Kylotan 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. :) –  Kaz Dragon Oct 27 '10 at 11:04
add comment

javascript? nobody use it? I think the google v8 engine could be quite funny to use.

share|improve this answer
    
V8 might be fun to embed, yeah. I may try and do a demo of that. Thanks for the idea :) –  Branan Oct 26 '10 at 15:02
add comment

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.

share|improve this answer
add comment

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

http://luabind.sourceforge.net/

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

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.