views:

1096

answers:

4

I'm wondering if it's possible to embed Ruby as a scripting language in Microsoft XNA, and what's the best way to do that. I'm looking for something like Xnua, except for Ruby.

I've stumbled upon Ruby.NET and IronRuby and both seem to be in very early stages, so I'm not sure how usable they are. Furthermore, I'm not sure if they'd work on Xbox 360. This topic at XNA forums says that IronPython wouldn't work, for example.

+2  A: 

It's almost guaranteed that IronRuby won't work on the Xbox, but if you just want to develop an XNA game for Windows, then you should be able to use it in the same way as for any other application.

I can't really tell you how you would go about doing that, just that it should be possible.

Jon Wood
That's interesting. I'm still wondering if that also applies to Ruby.NET or any other interpreters I don't know about. Maybe try to write my own 'simple' .NET binding that'd work on Xbox?
Firas Assaad
+7  A: 

IronRuby and IronPython do not work on the Xbox 360 because they are based on the DLR (Dynamic Language Runtime) and the DLR makes heavy use of System.Reflection.Emit types which are not currently available on the Xbox 360 .Net Framework (a modified version of the Compact .Net Framework).

As to the best way to do that, unfortunately that depends on the rest of your game. The work to enable IronRuby scripts to be evaluated in the context of your XNA program is fairly easy, check out this blog post for example. Beyond that you'd want to expose some interesting objects to your scripts and that's the bit that's entirely down to the rest of your game code/design. You could have a look at the scripting docs for Unity to get an idea of what types and commands to expose.

Leaf Garland
Would Ruby.net work on Xbox360? My understanding is that it's not based on the DLR, but I'm not even sure if it's still under development.
Firas Assaad
I don't know, but I wouldn't be surprised if Ruby.Net also made use of System.Reflection.Emit types. You could have a look at the source, just grepping for that namespace should tell you.
Leaf Garland
+1  A: 

While I agree with Leaf Garland's observations, let me offer you an alternative:

The "preferred" scripting language for games is Lua. For example the game Crysis and Far Cry uses LUA extensively. Flick over at wikipedia for a list of notable games that uses it.

In terms of using that with XNA, i've only scratched the surface since I just started myself with hobby XNA development, but what I do know is that you cannot use LUA directly in XNA. This is because LUA is built in C++ (unmanaged) and therefore you will not be able to deploy that to your XBOX360.

There is a project under development that is building an XNA version of lua at http://www.xnua.com/. It is also a free product and the source code is also available for download.

If the gaming industry belives that LUA is good enough for AAA commercial games, I would personally follow that direction as well (on the basis that they have way way more experience in that area than I do)

Ash M
I like Lua, but the question is pretty specific to Ruby because I already have a lot of Ruby code. The real answer is probably that it's not possible to embed ruby in XNA, but I still would like to see what other people think.
Firas Assaad
eek! please do not use LUA as it does not mean the same as Lua
RCIX
A: 

Why not use Ruby for PC development and Lua for 360?

EDIT: maybe this will be useful.

Geo
Because a lot of code has been already written in Ruby and I don't feel like rewriting all of it.
Firas Assaad