This project has moved and is read-only. For the latest updates, please go here.

Environment Persistence

Nov 15, 2011 at 8:55 AM

Just a quick question, but is there any way to persist variables and functions across evaluations/executions? This would be for an interactive environment where persistence of variables is needed.

Additionally, any update on the next release? Really looking forward to the seamless integration!

Thank you for your work, it's really awesome.

Nov 15, 2011 at 11:49 PM

Not quite sure what you mean because the default behaviour is to persist global variables and functions.

(The state is stored in the ScriptEngine, so just make sure you use the same ScriptEngine instance).

For example:

var engine = new ScriptEngine();
engine.Execute("var x = 5");
Console.WriteLine(engine.Evaluate(x)); // prints "5"
Nov 15, 2011 at 11:51 PM

In regard to the next release, sadly I have very little time available to work on it until Christmas... so hopefully around then.

(Skyrim is taking precedence at the moment!)

Nov 16, 2011 at 2:10 AM

My mistake, I've been using ScriptEngine.Evaluate()(so I could echo the result of the operation). Using Execute()maintains state but it doesn't return the result of the operation. I'm sure I'll figure it out :)


Thanks for your quick response and yeah, Skyrim is awesome :D

Nov 16, 2011 at 2:37 AM

No, Evaluate should be the same as Execute in this regard.  In fact, I'm sure it is because the silverlight console at uses Evaluate.

Nov 16, 2011 at 2:54 AM

I'm keeping persistent objects, this works (simplified code):

public string foo(command){
    return engine.Evaluate(command).ToString();
Killing the Execute call does not persist. Not sure why.

Nov 16, 2011 at 3:36 AM

Update: never mind. I worked out that the convoluted system I was using (ASP.NET MVC) wasn't correctly saving the ScriptEngine between ajax requests!

Seems like a silly question, but how do I transfer json objects in and out of the engine? I've looked through the documentation and the metadata and I'm just a bit confused. Should I be using ObjectInstance? 

Nov 16, 2011 at 5:23 AM
Edited Nov 16, 2011 at 5:36 AM

You can use Jurassic.Library.JSONObject.Parse and Jurassic.Library.JSONObject.Stringify or the javascript equivalents (JSON.parse and JSON.stringify).

Note that ObjectInstance-derived objects are tied to a specific ScriptEngine and you cannot move them between engine instances.  Using JSON is a good way of getting around this limitation.