Scripting

I dont intend on writing all the code in c# this time around. Having to recompile every time i make changes to my code  is a pain. So, this is where scripting comes in. I can just modify scripts at runtime instead of recompiling each time i want to tweak a freaking variable.

I found a ton of libraries that would allow me to embed an array of scripting languages. Here are the few that caught my attention:

  1. LuaInterface http://code.google.com/p/luainterface/
  2. Jint http://jint.codeplex.com/
  3. JavaScriptDotNet http://javascriptdotnet.codeplex.com/
  4. Jurassic http://jurassic.codeplex.com/
  5. IronJS https://github.com/fholm/IronJS
  6. RemObjects http://www.remobjects.com/script.aspx
  7. SpiderMonkeyDotNet http://spidermonkeydotnet.codeplex.com/releases/view/72907
  8. KSharp http://ksharp.codeplex.com/

If you checked all the links you’ll realize that most of them are for embedding javascript. Even tho it has its quirks its still my preferred language of choice. Lua is fast but I hate Lua’s backward syntax, who uses ‘do’ ‘then’ and ‘end’ anymore??

Lets Choose

XBox360 cant run unmanaged code (anything besides c#) so that rules LuaInterface out of the equation, so just a since its just a wrapper for the original c version(thank <your diety here>). So what’s left is the javascript alternatives :D….and the KSharp one.

Some of the libraries appears to be managed as well. I want to release my game for the xbox36, hence the reason for ruling out LuaInterface, so its best to choose a library that supports it. Dont want to dig myself in a hole.

SpiderMonkeyDotNet’s description says ” binding between the original JavaScript engine SpiderMonkey and the .Net platform”, which sounds like unmanaged code is in the mix. JavaScripDotNet’s description says the same about itself and the v8 engine. RemObjects’s JS Engine requires licensing which i dont want to get ( check here) so that option’s out the door as well. Iron packages for c# (IronPython, IronRuby) uses System.Reflection.Emit which isnt supported by the .NET compact framework, which is the framework that’s supported by the xbox360, so i suppose IronJS wont be any different. I know its bad to make an assumption like that based on one document i read about IronPython, but i’m too lazy to check out the others so deal with it.

This link states that Jurassic uses Reflection.Emit as well (should have known :/) so that’s out of the picture. This leaves me down to 2 libraries: Jint and KSharp.

Lets make a comparison of the 2 here:

Jint(Javascript Interpreter)

pros:

This isnt a wrapper, it’s a js interpreter written(with the lexer and parser generated by ANTLR) entirely in c#. This means it will run on the XBox 360. It’s very easy to use, well documented ad is fairly up to date. It is however not as fast as i’d like it to be. No typesafety, easier to code but languages like these tend to run slower(pro and con).

cons:

I’ve done some googling and the issue of speed is a problem users have where jint is concerned. Precompilation would be a very nice feature to help decrease load time. I should probably suggest that to the project managers. There’s no class support, so i gotta come up with some way to create classes in my scripts.

KSharp

pros:

Its description hits the nail on the head regarding what i want from an embedded scripting library. It targets both windows and the xbox 360. It compiles code at runtime so it should be fast.

cons:

Type safety. This should be a pro, but I really didnt want to see this when scripting. I dont have time for bothersome typecasting.

It’s last update was in 2009 and there are no bug trackers or documentation or anything for that matter!

Conclusion

I wont pick, I’m going to use them both. I’ll use KSharp for those scripts where get performance is necessary, and Jint when i want to relax and quickly hack up new game objects. Also, i’ve never used multiple scripting languages in a project so this should be fun :D. I’ll tell you guys how things work out next week.

See ya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s