Closed somecodingwitch closed 1 year ago
Hi @victoriaquasar,
Execute the function in the engine using the object variable that I got?
Script objects are instances of the ScriptObject
class, which has methods such as InvokeAsFunction
:
engine.AddHostType(typeof(Console));
var func = (ScriptObject)engine.Evaluate("(function(x) { Console.WriteLine(x); })");
func.InvokeAsFunction("Hello, world!");
You can also use C#'s dynamic
type:
engine.AddHostType(typeof(Console));
dynamic func = engine.Evaluate("(function(x) { Console.WriteLine(x); })");
func("Hello, world!");
Or pass the object back to the engine then execute it as function?
No problem at all:
engine.Execute("function invoke(x) { x(...Array.from(arguments).slice(1)); }");
engine.Script.invoke(func, "Hello, world!");
Good luck!
Thanks!
Let's supposed I have an interop object, a result from the
engine.EvaluateScript(...)
method as anobject
. Now let's suppose that result is a JavaScriptFunction
, I have that in C# now.How can I:
object
variable that I got?For example, in Jint I can do: