Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Call known method by name

$
0
0
Hello!

The following test code compiles and runs as expected:
using (var engine = new V8ScriptEngine())
{
    engine.Execute("function foo(x) { return x; }");
    Console.WriteLine(engine.Script.foo(123));  // writes "123"
    Console.WriteLine(engine.Script["foo"](456));  // writes "456"
    Console.WriteLine(engine.Invoke("foo", 789));  // writes "789"var host = new HostFunctions();
    ((IScriptableObject)host).OnExposedToScriptCode(engine);
    var del = (Delegate)host.func(1, engine.Script["foo"]);
    Console.WriteLine(del.DynamicInvoke(987));  // writes "987"
}
Are you doing something differently? What framework version are you using?

Cheers!

Viewing all articles
Browse latest Browse all 2297

Trending Articles