The relationship between Jint and JavaScript

I am looking for a way to communicate (round-trip) between Jint and C #.

Is there any way? I have no problem running JavaScripts in Jint after loading them into the engine, but I still have a problem with callbacks on the other hand - from JavaScript back to C # (maybe using some ObjectForScripting? Or other predefined settings?) Thanks

+4
source share
1 answer

In C #, specify the class using the 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);
+1
source

Source: https://habr.com/ru/post/1618114/


All Articles