I am reading a book on Game Development in which they show you how to make scripts for your game in Lua. They program Lua and use it from C++, but I was wondering if there is a library or API to use Lua from C#: specifically from XNA to develop games for PC and XBox 360?
|
|
This is were I would point you (http://www.xnua.com/xna_lua_xnua), but it hasn't been updated for a long time. C# is great language, and could in a sense be used as a scripting language within your c# game. Nick Gravelyn has created some nice tutorials about tile engine (http://blog.nickgravelyn.com/downloads/#tileengine) and used a custom scripting engine to fire off dialog. He has also has a basic example when he learned about the "yield" keyword: http://blog.nickgravelyn.com/2010/02/the-magic-of-yield/ |
|||||||||||||
|
|
If you're looking for scripting in C#, definitely take a look at IronPython. It's not just a python API for C#, it is actually a completely separate python implementation which compiles to the same CLR assembly (with the same performance) that C# does, but can be interfaced with as a scripting language. Any Lua wrapper for C# would be much slow due to the overhead of Marshalling. |
|||
|
|
|
As Sean said, IronPython is worth looking at. IronPython is actually one of a few dynamic language implementations for .NET targeting the Dynamic Language Runtime (DLR). There is at least one open source project aimed at implementing Lua on the DLR (like this one), but I'm not sure if there are any implementations near completion. A well-implemented set of DLR bindings for Lua should provide performance on par with IronPython and IronRuby, and would be much faster than a Lua wrapper. For the sake of comparison, IronPython generally performs better than CPython (sometimes significantly better). Note: As ElementCy states below, DLR languages are generally not supported on the Xbox 360. However, there is an "interpreted mode" in the DLR. I don't know enough about it to say for sure, but it might be possible to get IronPython (or other DLR language implementations) to run on the Xbox 360 in interpreted mode, though performance would certainly suffer. It might be worth asking someone on the DLR team whether they know this to be possible. If not, the Xbox 360 should get Reflection.Emit support as part of upcoming Silverlight support. If and when that happens, I imagine getting the DLR up and running on the Xbox 360 won't be a problem. |
|||||||||||||||
|
|
The best solution I could give you is to just script in C#. You can compile them at runtime when you target windows and compile them before hand for the xbox. (as a dll) That would be the easiest solution. You could also do it in VB.NET or any .NET language. (not sure about the scripting ones though) Basically, I'm saying to have your scripts in their own dll. You can have them compile at runtime on Windows. (do you really want them to do this on the xbox 360?, you can't update your games on there, at least I don't think so) I can understand your frustration, I wanted to use Lua as well. To sum it up: 1) Have it built at runtime on Windows 2) Build it before hand for the Xbox 360 That's what I recommend. |
|||
|
|
|
|||||
|
|
It doesn't technically answer your question (doesn't work on the xbox), but LuaInterface allows Lua integration with C# relatively painlessly. |
|||
|
|
