Reputation: 859
I am looking for a way to communicate (back and forth) between Jint and C#.
Is there a way? I have no problem of running JavaScripts in Jint after loading them to the engine but I still have an issue getting the callbacks on the other hand - from the JavaScript back to C#(maybe using some kind of ObjectForScripting? or other predefined settings?) Thanks
Upvotes: 4
Views: 900
Reputation: 3729
In C#, provide a class with a method you want to run.
public class JavaScriptHelper {
public string Method(string input) {
return String.Concat("Hi", input);
}
}
Then pass the class to the engine.
var engine = new Engine();
engine.SetValue("helper", new JavaScriptHelper());
var source = @" var result = helper.Method('Hello');"
engine.Run(source);
Upvotes: 1