up vote 8 down vote favorite
share [fb]

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#?

link|improve this question
4  
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. – MindWorX Jan 5 at 15:02
2  
Why do you even need a scripting language? Which bennefits are you expecting? – Psykocyber Jan 5 at 15:04
2  
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. – Cloudanger Jan 5 at 15:50
1  
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). – Jonathan Dickinson Jan 6 at 14:15
1  
Also, don't neglect visual scripting (similar to the Staredit - the Starcraft 1 editor). – Jonathan Dickinson Jan 6 at 14:17
show 2 more comments
feedback

2 Answers

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
 a**b
 ");
 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)
        Console.WriteLine(item);
    Console.WriteLine(example.lunch);
link|improve this answer
+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 ;-) – tobsen Jan 5 at 19:50
1  
Lua is a pain to set up though. I believe the time it will take you to get each working makes IronPython better alone. – ClassicThunder Jan 5 at 21:09
feedback

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.

link|improve this answer
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. – Josh Petrie yesterday
feedback

Your Answer

 
or
required, but never shown

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