I am thinking about giving a go to one of my ancient ideas for a game. The core point of this game would be the possible level of functional customization of the game environment and objects (such as modifying the behavior of a space ship weaponry). For this the game would need to be scriptable. Also I don't aim to commercialize it, it is merely an interesting programming challenge for me.

As I am mostly a .NET guy I will use XNA/C# for the game itself. For the scripting I think about going with Python or Lua. I have previous experience with Python and have nothing against it as a language. Lua on the other hand is almost completely new to me, besides some minor World of Warcraft addons modifications I did here and there, and it looks promising. So here is my question:

What are the pros and cons of Lua vs. Python as a scripting language for XNA/C# platform?

Is one of them considerably easier to use with XNA/C#? Has one of them some specific advantages or disadvantages when used with XNA/C#? Why would you recommend one over the other for XNA/C#?

  • 4
    \$\begingroup\$ I know you're not asking for alternatives, but just in case you don't know, C# is also a valid scripting language, and since you're using C# it's very low maintenance. \$\endgroup\$
    – William
    Commented Jan 5, 2012 at 15:02
  • 2
    \$\begingroup\$ Why do you even need a scripting language? Which bennefits are you expecting? \$\endgroup\$ Commented Jan 5, 2012 at 15:04
  • 2
    \$\begingroup\$ Both of them are popular, professionally used and definitely capable of doing the scripting part. It's just a matter of taste for 99% of the applications. Python has a better standard library and in my opinion is more user-friendly language. \$\endgroup\$
    – Cloudanger
    Commented Jan 5, 2012 at 15:50
  • 1
    \$\begingroup\$ Along the lines of 'have you considered?' Have you considered Boo? It's designed for scripting, instead of so happening to become a scripting language. Similar to IronPython it has built-in helpers for hosting (and can even interpret for targets like the XBox). \$\endgroup\$ Commented Jan 6, 2012 at 14:15
  • 1
    \$\begingroup\$ Also, don't neglect visual scripting (similar to the Staredit - the Starcraft 1 editor). \$\endgroup\$ Commented Jan 6, 2012 at 14:17

2 Answers 2


I can't compare the two, as I've only had experience embedding IronPython in a C# game so far. Here's what I like about it though:

1) It's easy! Download the IronPython DLLs, add reference in project,

 using IronPython.Hosting;

 var engine = Python.CreateEngine();
 var product = engine.Execute<System.Numerics.BigInteger>(@"
 print ' '.join(['hello', 'from', 'ironpython!'])
 a = 123456789
 b = 10
 Console.WriteLine("a**b={0}", product);

2) As you can see from the above example, IronPython actually converts to BCL classes where it can. the result of the script is a System.Numerics.BigInteger rather than a PyObject

3) The dynamic keyword in C# was made for interop situations where you don't have the static type available:

    dynamic example = engine.Execute(@"
class Example(object):
  def __init__(self):
    self.breakfast = ['ham','spam','eggs']
    self.lunch = 'BRAIINNNZ'
Example() # return an example");

    foreach(string item in example.breakfast)
  • \$\begingroup\$ +1 for the good example which shows how easy it is to get iron python runnning.... although that was not was OP was asking for ;-) \$\endgroup\$
    – tobsen
    Commented Jan 5, 2012 at 19:50

IronPython and C# go well together, IronPython can be added to C# to give it boost in performance. So if your writing games then Python calls within C# are an advantage. Python itself can't make use of XNA but can make use of Directx something C# can't do directly.

  • 1
    \$\begingroup\$ FWIW, Python can't make use of DirectX "directly" either -- it interacts with it via wrappers based on the fact that D3D is a C/COM API. This is exactly how you can access DirectX from C# as well. \$\endgroup\$
    – user1430
    Commented Jan 22, 2012 at 18:00

Not the answer you're looking for? Browse other questions tagged .