Hi ssylvain,
First, you probably need to add a
Next, you're getting the error because
You probably either want to do something like this:
or something like this:
Cheers!
First, you probably need to add a
return
statement to DoStuff
; otherwise it returns undefined
.Next, you're getting the error because
v1
is a .NET variable, but engine.Script.v1
tries to retrieve a nonexistent global value named v1
from the script engine.You probably either want to do something like this:
dynamic v1 = engine.Evaluate("new MyClass()"); var res1 = (int)v1.DoStuff(2); Console.WriteLine(res1);
engine.Evaluate("v2 = new MyClass()"); var res2 = Convert.ToInt32(engine.Evaluate("v2.DoStuff(2)")); Console.WriteLine(res2);