Log in

tobes31415 in tobes31415_code

Initial Research for Embedded Scripts in .Net Applications

I did a bit of looking around yesterday at my planned personal projects. One of my requirements is a scripting language so I decided to do some light reading on LUA script. LUA is the scripting language I had chosen to use because its lightweight, I know it is currently used for World of Warcraft and a whole slew of other games and applications and already has C# libraries. One annoyance I see is that the syntax is that its vaguely reminiscent of the dark ages when I developed in basic and there are some limitations compared to other languages due to it's lightweightedness.

What would be nice is to do my scripting in ECMAscript assuming it could be made fast enough. It has curly brackets that make things easy to follow even, and its been proven that it can even be used for really complex things when the need arises. Oh, and the minor little fact that JavaScript which is pretty much everywhere is ECMAscript, so the language is guaranteed to be refined over time and everyone already know how to use it.

Is ECMAscript too heavy for what I want to use it for? Well, what do I want to use it for?
* scripting game board rules
* scripting NPC behaviors
* serializing queries and running them remotely

The last one I think would be really sweet. The general idea being something like "I want to find a Car with 2 doors, comes in the color blue, age < 10, and cost is < (10 - Age) * 1000". The first three are relatively easy, but the last one would require exposing the server to your custom SQL (which is a no-no) instead you would query on the first three using a provided interface, and then filtering out the ones that don't match the last criterion after you receive the list. If instead of calling a specific query interface we send a short script that will select what it is we want then we can have a much more rich interface without needing to have a gazillion overloads exposed.

So, if I want to code in ECMAscript in .Net, what are my options?

* JScript.Net
* Rhino (currently being ported to C#)

... That is a very short list.

JScript.Net despite being JScript based is primarily a compiled language. I'm pretty sure it uses reflection and emitting code at run time to simulate "interpretting" on the fly. This would be ridiculously expensive for any kind of dynamic use... which entirely defeats the purpose of having a scripting language in the first place. (so um... wtf?)

Rhino is a bit of a mystery. It was originally developed for java and presumably works well enough, but the pages I've seen regarding the C# port are several years old. I suspect it may have been abandoned.

Create my own implementation?
javascript and C# have many similarities. It should be possible to use c# code for the logic. And I could use all the funky new .Net 3.5 syntax to make coding the things that do need to be hardcoded easy.
A major bonus if I made my own implementation is that I'd have access to the parse tree and then could serialize scripts directly to and from binary mode (wickedly fast as compared to text). I would also be able to add a few extensions to the language such as minimal support for multi threaded environments or coroutines.

This would be cool but it'd be a lot of work too. If I went with LUA, I wouldn't be able to do the remote query thing but it'd still be good for my main purposes


January 2009

Powered by LiveJournal.com