Embedded scripting language

S

skotl

Hi all,

I'm writing an application that will allow users to specify their own
rules to match against certain patterns.
Initially I figured that I would offer my own interpreter (byte[14] ==
7 && byte[17] begins 'abc') but I quickly realised that I can offer
far more flexibility by offering a completely interpreted and function
rich language.
The core app is written in C# with CLR, so my two choices seem to be
Lua (linked in and interpreted at runtime) or C# (not sure how I would
call/compile this).

Has anyone else done this kind of work and what language/framework
would you recommend?

Regards
Skotl
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

skotl said:
I'm writing an application that will allow users to specify their own
rules to match against certain patterns.
Initially I figured that I would offer my own interpreter (byte[14] ==
7 && byte[17] begins 'abc') but I quickly realised that I can offer
far more flexibility by offering a completely interpreted and function
rich language.
The core app is written in C# with CLR, so my two choices seem to be
Lua (linked in and interpreted at runtime) or C# (not sure how I would
call/compile this).

Has anyone else done this kind of work and what language/framework
would you recommend?

You can compile and load C# code when running. The necessary
classes are in the .NET framework.

A code snippet:

CodeDomProvider comp = new CSharpCodeProvider();
CompilerParameters param = new CompilerParameters();
param.GenerateInMemory = true;
param.ReferencedAssemblies.Add("System.dll");
CompilerResults res =
comp.CompileAssemblyFromSource(param, sourcecode);
Assembly asm = res.CompiledAssembly;
o = asm.CreateInstance(classname);


Arne
 
S

Samuel R. Neff

I'm pretty sure Fiddler has ability to create tiny plugins in
JScript.NET so you can look at that as an example. I think it
actually has a mini-IDE built in and everything.

HTH,

Sam
 
S

skotl

You can compile and load C# code when running. The necessary
classes are in the .NET framework.

That's nifty - thanks Arne.

Is there a way to restrict their access to system objects / calls? (I
wonder whether this would be controlled by the number of
ReferencesAssemblies.Add() you would specifiy?).

The reason I ask is that it would be great to inherit the basic math
and string functions, as well as having Microsoft provide the
interpreter(!), but I'd not be as keen that the add-on writer could go
off and do anything he wanted to database, web services, etc.

Cheers
Scott.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Is there a way to restrict their access to system objects / calls? (I
wonder whether this would be controlled by the number of
ReferencesAssemblies.Add() you would specifiy?).

The reason I ask is that it would be great to inherit the basic math
and string functions, as well as having Microsoft provide the
interpreter(!), but I'd not be as keen that the add-on writer could go
off and do anything he wanted to database, web services, etc.

C# is not the right language for a such a restricted environment.

I think you will need an interpreted language instead of a compiled
..NET language.

The no assemblies trick is insufficient. mscorlib has plenty
of potential dangerous classes.

Arne
 

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