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

New Post: Possible to add a global function?

0
0
Knowing that I can add global instances of host objects to the script engine like this:
engine.AddHostObject("random", new Random());
engine.Execute("Console.WriteLine(random.NextDouble())");
I wonder whether it would be possible to directly introduce global functions to the script engine so that I could directly execute this function in my script without specifying an object.

E.g. something like:
engine.AddHostFunction("add", delegate(int a, int b) { return a + b });
engine.Execute("Console.WriteLine(add(1,2))");
Does this sound reasonable? Is this possible?

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images