This project has moved. For the latest updates, please go here.

Create extended function for script

There is a .NET class NativeFunctionObject used to define an interface in C# for script execution. Create the instance of this class and add it into script context.

All global variables, objects and functions are managed as property of global object. ReoScript provides the API to access global object, see ScriptRunningMachine.

Create function in .NET program

Create the ScriptRunningMachine as below:
ScriptRunningMachine srm = new ScriptRunningMachine();

Create and add extended function:
srm["hello"] = new NativeFunctionObject("hello", (ctx, owner, args) => {
    Console.WriteLine("Hello World!");
    return null;
});

Call this function in script:
hello();

The "Hello World!" will be printed out:
Hello World!

Learn more about NativeFunctionObject.

Func<> interface

A function defined as delegate in .NET program also can be invoked in script.
srm["myfunc"] = (Func<int,bool>)((a) => {
    return a > 10;
});

Difference between Func<> and NativeFunctionObject

  • Func<> has no context of script
  • Func<> has fixed length of arguments

Last edited Dec 26, 2013 at 6:31 AM by unvell, version 3