Awesome

Jan 18, 2010 at 2:18 AM

Just wanted to say that you put a lot of work into this and I gotta say I'm impressed.

I'm just playing around with it now but i was wondering if it was possible to have a script context where i can add and retrieve variables after interpretation.

for example:

ScriptContext context = new ScriptContext();
context.add("myString","string value");

ScriptingEngine.Interpret(program,context);

//retrieve modified string from script string someValue = context["myString"];

Even better would be if objects written in C# could be exposed to the script or some way. Or just callbacks or something. Any way it could communicate with the main app.

Of course this probably falls outside of the scope or purpose of this project.

Just wanted to say the stuff i tested seemed pretty impressive.

 

Coordinator
Feb 19, 2010 at 11:50 AM
Edited Feb 19, 2010 at 11:51 AM

Hi TheAso,

thanks for this feedback and sorry to respond so late; i've been so busy since my last post on this project that i didn't even have the time to follow it.

Your suggestions are very interesting. In fact, the purpose of the ScripEngine class is to provide simple ways of interacting with the scripting API.

However it's still under construction and does not provide right now, all the utility methods one should expect. Yet, it's quite easy to improve the ScriptEngine class by yourself.

For example, you could add another Interpret method with a first argument of type Program and a second one of type Dictionary<string, Variable>.

The logic of this method could be borrowed from the existing Evaluate method. After calling such a method, the dictionary (passed as second argument) would contain modified parameters.

Of course a better approach would be to have a ScriptContext instance as the second parameter (as you suggested). This could keep not only input parameters, but also environment variables and many more.

Since this implies changes in the scripting API core (specially for allowing the retrieval of context elements), i will look at it further. I'm also working on a better way to manipulate native .Net objects from the script.

Well, hope this reponds to your preoccupations.