4

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

user1322801
  • 839
  • 1
  • 12
  • 27

1 Answers1

1

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);
Chet
  • 3,461
  • 1
  • 19
  • 24