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


NativeFunctionObject is a class used to define an interface of function. It is typically used to make more extended functions available during script execution.

Constructor of NativeFunctionObject:
new NativeFunctionObject(string name, Func<ctx, owner, args> body)

  • name - the name of this object (not name of function)
  • body - the function body of .NET code
    • ctx - the script run-time context, it contains the info about current call-stack and local variables
    • owner - owner of this function (equals to this keyword)
    • args - argument list of object[]

Add function in .NET program

An example to make ReoScript can start a windows process up with given exec-file path:
ScriptRunningMachine srm = new ScriptRunningMachine();

See more details about ScriptRunningMachine.
srm.SetGlobalVariable("exec", new NativeFunctionObject("exec", 
    (ctx, owner, args) =>
        if (args.Length < 0) return null;

        string exeName = Convert.ToString(args[0]);

        return null;

Then call this function in script:

Add function as method of object in .NET program

Create object in .NET program:
ObjectValue obj = new ObjectValue();

Learn more about ObjectValue.
Add method into object:
obj["sayHello"] = new NativeFunctionObject("sayHello", (ctx, owner, args) =>
    Console.WriteLine("Hello World!");
    return null;

Add object into script context:
srm["obj"] = obj;

Call in script:

Hello World!

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