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

New Post: Re-using script object

$
0
0
Hi ssylvain,

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);
or something like this:
engine.Evaluate("v2 = new MyClass()");
var res2 = Convert.ToInt32(engine.Evaluate("v2.DoStuff(2)"));
Console.WriteLine(res2);
Cheers!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images