Scripting (ECMA script) solution for .NET app?

P

Passiday

Hello,

I am looking for a stable solution for my dotNET projects, that would
allow to add scripting capabilities to my apps. The idea is to allow
application users to write their own scripts that impact the behaviour
of the application. It totally makes sense to offer the scripting with
well established standard scripting language, like ECMA script (ie
standard on what JavaScript, JScript and Adobe ActionScript are
based).

The solution should have the following features:
1) Script error reporting -- it there is a syntax error in the script,
there must be a way to get appropriate error information to tell user
so that he can fix his macro
2) Ability to access specifically exposed application objects from the
scripting scope
3) It would be great if the solution could be used also from
environments like ASP.NET, ie, light enough to allow use from web
applications that spawn several simultaneous sessions.
4) JIT compiling of the script is Ok, if it is transapent enough not
to mess up things if there's some runtime error and application can
not provide decent error context to the user.

In my search for solution, I contemplated using some web browser
control -- feed it with script and let it execute inside the control,
but it feels kind of heavy (especially if I'd like to use it in
ASP.NET), given I am looking only for scripting sandbox.

Thanks for any hints!

Passiday
 
P

Passiday

YOu should post to an ASP.NET newsgroup.

Arnlod, thanks for messing the thread up. If you read carefully, this
is not about web app development, and not about client-side scripting
of web app.

This, of course, is perhaps more general .NET question rather than
focused on C# language peculiarities, but if the scope of this forum
would be just C# syntax, then most of the subjects here would deserve
your style of reply.

Passiday
 
M

Mr. Arnold

Passiday said:
Arnlod, thanks for messing the thread up. If you read carefully, this
is not about web app development, and not about client-side scripting
of web app.

This, of course, is perhaps more general .NET question rather than
focused on C# language peculiarities, but if the scope of this forum
would be just C# syntax, then most of the subjects here would deserve
your style of reply.

I don't think there was need here for you to get up on your high horse. You
had the words ASP.NET and Web in the post. Therefore, you got my response.
And that's "Arnold" not "Arnlod".
 
J

Jesse Houwing

Hello Passiday,
Hello,

I am looking for a stable solution for my dotNET projects, that would
allow to add scripting capabilities to my apps. The idea is to allow
application users to write their own scripts that impact the behaviour
of the application. It totally makes sense to offer the scripting with
well established standard scripting language, like ECMA script (ie
standard on what JavaScript, JScript and Adobe ActionScript are
based).

The solution should have the following features:
1) Script error reporting -- it there is a syntax error in the script,
there must be a way to get appropriate error information to tell user
so that he can fix his macro
2) Ability to access specifically exposed application objects from the
scripting scope
3) It would be great if the solution could be used also from
environments like ASP.NET, ie, light enough to allow use from web
applications that spawn several simultaneous sessions.
4) JIT compiling of the script is Ok, if it is transapent enough not
to mess up things if there's some runtime error and application can
not provide decent error context to the user.
In my search for solution, I contemplated using some web browser
control -- feed it with script and let it execute inside the control,
but it feels kind of heavy (especially if I'd like to use it in
ASP.NET), given I am looking only for scripting sandbox.

Thanks for any hints!

have a look at:
http://msdn.microsoft.com/en-us/library/ms974577.aspx
 
A

Arne Vajhøj

Passiday said:
I am looking for a stable solution for my dotNET projects, that would
allow to add scripting capabilities to my apps. The idea is to allow
application users to write their own scripts that impact the behaviour
of the application. It totally makes sense to offer the scripting with
well established standard scripting language, like ECMA script (ie
standard on what JavaScript, JScript and Adobe ActionScript are
based).

The solution should have the following features:
1) Script error reporting -- it there is a syntax error in the script,
there must be a way to get appropriate error information to tell user
so that he can fix his macro
2) Ability to access specifically exposed application objects from the
scripting scope
3) It would be great if the solution could be used also from
environments like ASP.NET, ie, light enough to allow use from web
applications that spawn several simultaneous sessions.
4) JIT compiling of the script is Ok, if it is transapent enough not
to mess up things if there's some runtime error and application can
not provide decent error context to the user.

In my search for solution, I contemplated using some web browser
control -- feed it with script and let it execute inside the control,
but it feels kind of heavy (especially if I'd like to use it in
ASP.NET), given I am looking only for scripting sandbox.

The JScript.NET compiler is callable from C# code.

You get the source as a string, you compile it to an in memory
assembly, you load it and instantiate classes from it.

Code snippet:

string src = "...";
CodeDomProvider comp = new JScriptCodeProvider();
CompilerParameters param = new CompilerParameters();
param.GenerateInMemory = true;
param.ReferencedAssemblies.Add("System.dll");
param.ReferencedAssemblies.Add(System.Reflection.Assembly.GetExecutingAssembly().Location);
CompilerResults res = comp.CompileAssemblyFromSource(param, src);
Assembly asm = res.CompiledAssembly;
X o = (X)asm.CreateInstance("C");

Arne
 
A

Arne Vajhøj

Mr. Arnold said:
I don't think there was need here for you to get up on your high horse.
You had the words ASP.NET and Web in the post.

Hm.

He wrote:

"It would be great if the solution could be used also from
environments like ASP.NET"

It seems rather obvious that it is not an ASP.NET solution
he is looking for.

Why not read the questions a bit more carefully before
asking them to go to another group?

Arne
 
P

Pavel Minaev

I am looking for a stable solution for my dotNET projects, that would
allow to add scripting capabilities to my apps. The idea is to allow
application users to write their own scripts that impact the behaviour
of the application. It totally makes sense to offer the scripting with
well established standard scripting language, like ECMA script (ie
standard on what JavaScript, JScript and Adobe ActionScript are
based).

The solution should have the following features:
1) Script error reporting -- it there is a syntax error in the script,
there must be a way to get appropriate error information to tell user
so that he can fix his macro
2) Ability to access specifically exposed application objects from the
scripting scope
3) It would be great if the solution could be used also from
environments like ASP.NET, ie, light enough to allow use from web
applications that spawn several simultaneous sessions.
4) JIT compiling of the script is Ok, if it is transapent enough not
to mess up things if there's some runtime error and application can
not provide decent error context to the user.

In my search for solution, I contemplated using some web browser
control -- feed it with script and let it execute inside the control,
but it feels kind of heavy (especially if I'd like to use it in
ASP.NET), given I am looking only for scripting sandbox.

If you specifically want an EcmaScript implementation, then the only
good choice I'm aware of for .NET presently is JScript.NET. From what
I know, it's a pretty faithful implementation, but it also has a
number of extensions along the lines of the abortive EcmaScript 4
standard (most notably, explicit type declarations and class-based
OO).

The good part of it is that it comes with the framework, so no need to
redistribute additional libraries with your application, and no
permission problems setting them up. The bad part is that it hasn't
really been developed since JScript 8.0 (which was part of .NET 2.0 /
VS2005), and even then it already wasn't first-class on .NET - for
example, there's no syntax to declare or even reference a generic type
or method (but, of course, since it's late-bound, it can still work
with instances of generic types if it gets them from elsewhere). It's
not officially deprecated, but in effect, I would take the lack of
development in several years as a strong indication of that.

Moving on to hotter things, these days, the scripting craze on .NET is
all about DLR (Dynamic Language Runtime). This is presently available
separately, and will come as a stock component in .NET 4.0. There was
an EcmaScript implementation announced for it - "Managed JScript":

http://blogs.msdn.com/deepak/archive/2007/05/02/managed-jscript-is-availaible.aspx

However, I haven't heard much about it for a long time, so I don't
know of the present status of the project, or release schedule.

The most well-developed language on DLR today (and, indeed, the one
for which DLR was originally designed) is IronPython:

http://www.codeplex.com/IronPython

It implements Python 2.x, and is itself at a second major release, so
it's quite stable and well-polished. Python itself is also a very
popular choice for a scripting language, and a very clean language in
general, so unless you really want EcmaScript specifically, I would
suggest taking a closer look. It also seems that IronPython is
destined to become a future scripting language of choice in MS
products alongside PowerShell (the former for scripting within the
app, the latter for scripting/automation outside the app).

There's also IronRuby, which is also a fairly interesting project, but
so far it seems to be much less stable, and hasn't had a final 1.0
release yet.
 
M

Michael B. Trausch

I am looking for a stable solution for my dotNET projects, that would
allow to add scripting capabilities to my apps. The idea is to allow
application users to write their own scripts that impact the behaviour
of the application. It totally makes sense to offer the scripting with
well established standard scripting language, like ECMA script (ie
standard on what JavaScript, JScript and Adobe ActionScript are
based).

You could look at Boo, which is a Python-like language for .NET. There
is even an interactive interpreter available for it. Also, (the
obvious for this group) check out C# --- you can actually compile C#
snippets on-demand, at least in Mono (so you should be able to do it
for the MS implementation of the CLR, too). Mono has a C Sharp "shell"
available as a demo of that functionality:
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> using System.IO;
csharp> File.Exists("hello.cs");
true
csharp> quit;
null

--- Mike
 
A

Arto Viitanen

Arne said:
The JScript.NET compiler is callable from C# code.

You get the source as a string, you compile it to an in memory
assembly, you load it and instantiate classes from it.

I have been testing Lua with LuaInterface
(http://luaforge.net/projects/luainterface) and it seems fine. For
language, Lua is ok and the LuaInterface gives more control than
JScript.NET on what objects are shown to the scripts. On my test
program, I like to show three objects of the program to scripts:

----------
private void RegisterLua()
{
lua = new Lua();
lua["log"] = LogManager.GetLogger("LuaInterpreter");
lua["ppp"] = this.ppp;
lua["webpage"] = this.outputWB;
Type typ = this.GetType();
MethodInfo inf = typ.GetMethod("ShowLine");
lua.RegisterFunction("ShowLine", this, inf);
}

public void ShowLine(string msg)
{
this.outoutRTB.AppendText(msg);
this.outputRTB.AppendText(Endironment.NewLine);
}
----------

where ppp is the object I am testing, outputWB is WebPage (ppp is as
name implies PPP access to a embedded webserver) and outputRTB is is a
RichTextBox used in output panel. The Lua code is read as:

....

string cmd = this.inputTB.Text;
object[] returns = lua.DoString(cmd);
....

On Lua script, I can use objects 'log' (log4net logger), 'ppp' and
'webpage' and function 'ShowLine'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top