Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I have a game written in C++. But I want to add some modding or scripting functionality to it. How would one go about adding a scripting functionality to your game?

share|improve this question
The exact steps depend massively on the language you want to add. Have a look at… – tenpn Jul 15 '10 at 12:03
up vote 20 down vote accepted

First of all, you should decide what part of your game is scripted. One option is to have a fully scripted game in the sense that while the time-critical backend operations are coded in C++, all the game logic is in the scripting language. Designers use the backend as a library called from the high level scripting language. On the other extreme, you can have few specific places where scripts are used, such as the user interface or scripted sequences, with the majority of the game code is still in C++. There are advantages to each approach (speed, flexibility, compilation time, scope of game, etc.), but you need to decide that beforehand.

Once you know how you want to use scripting, you now need to decide if you're going to use an existing scripting language or your own. Today there are many scripting languages to choose from with different design goals and target audiences, so I'm not sure if it's worth creating your own anymore. You can read about implementing your own scripting engine here.

Some popular scripting languages include Lua, which is lightweight and easy to embed. It uses a stack for communication between the host and embedded language and it was successfully used in many professional games. Another option is AngelCode, which allows you to call C and C++ functions directly. Python and Ruby are a bit more complex to embed but once you have done that they are very pleasant to program in. If you want to embed Python then take a look at Boost.Python. You can also try embedding JavaScript and take advantage of the fast scripting engines developed for browsers. For my game we are using Google's V8 engine which is very fast and easy to embed, but Mozilla's SpiderMonkey is another option.

share|improve this answer
I've implemented a scripting language for my current game project, and the primary advantage is total control over language primitives. Prebuilt scripting solutions are generic, and you may not need all of the features that they provide. You absolutely should not think about rolling your own language unless you're certain that you can make something that's better for your game than an existing solution. – Jon Purdy Sep 28 '10 at 16:29
Personally I like Guile, it has great integration with C. Only problem is the speed, but with the 2.0 release in the next couple of months that should improve too. – Joe D Nov 14 '10 at 1:38
Excellent answer. The first paragraph can be summed up as "game developers create an API which is consumed for content." – ashes999 Oct 23 '11 at 17:52

The most popular language:

See Lua (Programming language)
and Lua (Programming langugae) - C API


IBM has a great article on this: Embedding LUA

share|improve this answer

I wrote a post about embedding GameMonkey script to a game using DragonFire SDK here: Basically the idea is to expose your C\C++ functions to your chosen scripting language and use them from your script. In my tutorial, I exposed 2 functions from DragonFire SDK. At game start, I call onStart function from script and on update, I call onTimer function from script.

Hope that helps!

share|improve this answer
I've also uploaded a video demo here: – astk Sep 24 '10 at 3:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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