tags:

views:

322

answers:

3

I recently had to take a quick look at Adobe InDesign server. In this enviroment you write your interactions with the servers libs via JavaSscript.

This got me thinking, how could I use the Javascript language within a C# application so that I could expose set bits of functionality of my API/framework and allow others to write small plugins with JavaScript.

As JS is a pretty popular language so I would have thought that I wouldnt have to go writing my own impterpretor or anything, but I could be wrong. Any ideas where I would start with something like this?

Cheers, Chris.

+2  A: 

Check this question:

Referencing Google’s V8 engine from a .NET app

This article might be interesting:

Evaluating JavaScript code from C# (using MS JScript engine)

CMS
CMS, this very interesting but it seems odd that in order to parse JS I would use have to use an unmanaged C++ engine and stick build wrapper classes for interop. Still, as I said looks interesting. Worth a play.
Owen
Thanks for the update, interesting stuff again.
Owen
You're welcome Owen.
CMS
+1  A: 

This will be much easier soon when Microsoft releases Managed JScript (http://blogs.msdn.com/deepak/archive/2007/05/02/managed-jscript-is-availaible.aspx)

If you're not beholden to Javascript for now, I'd check out IronPython (http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython) - the hosting API is identical to what Microsoft will release for JS and about as easy as it could possibly be, and switching between the 3 DLR languages (IPy, IronRuby, and Managed JS) is trivial.

Edit: Oops, apparently it's available now as part of ASP.NET Futures - I thought it was only in Silverlight; go to it!

Paul Betts
Actually was just looking at IPy as we speak. Nice to see this is avaliable in ASP.NET futures. Incidently, when I hear about dynamic languages Silverlight always gets mentioned, any idea why this is?
Owen
This is because Silverlight has an embedded copy of IPy/IRb built-in, so you can write Python code to control your SL applet. Silverlight was one of the main scenarios that MS designed the DLR for.
Paul Betts
Why would Silverlight benefit more from the DLR than any other asptect of the .NET framework?
Owen
A: 

Try Javascript .NET:

http://javascriptdotnet.codeplex.com/

It implements Google V8. You can compile and run Javascript directly from .NET code with it, and supply CLI objects to be used by the Javascript code as well. And V8 is probably the best engine ever created in terms of performance, it generates native code from Javascript.

Jordane Green