-
Notifications
You must be signed in to change notification settings - Fork 35
NativeFunctionObject
Jing Lu edited this page May 13, 2013
·
12 revisions
NativeFunctionObject is a class provided by ReoScript to define an interface of function which created in .Net programs but called in script. This is typically used to extend features for ReoScript, make it more powerful and more native ability to do something.
Constructor of NativeFunctionObject:
new NativeFunctionObject(string name, Func<ctx, owner, args> body)
where
- name - name of function
- body - native function body
- ctx - runtime context
- owner - function owner
- args - arguments
An example to make ReoScript can start a windows process up with given exec-file path:
ScriptRunningMachine srm = new ScriptRunningMachine();
srm.SetGlobalVariable("exec", new NativeFunctionObject("exec",
(ctx, owner, args) =>
{
if (args.Length < 0) return null;
string exeName = Convert.ToString(args[0]);
System.Diagnostics.Process.Start(exeName);
return null;
})
);
Then call this function in script:
srm.Run(" exec('notepad.exe'); ");
The Windows Notepad should be started up.