Skip to content
Jing Lu edited this page May 16, 2013 · 15 revisions

ReoScript supports directly to access .Net object in script. The following behavior are available:

Enable DirectAccess

By default, ScriptRunningMachine disallows script to access .Net object. To enable DirectAcess, you need to change the WorkMode of ScriptRunningMachine as below:

ScriptRunningMachine srm = new ScriptRunningMachine();
srm.WorkMode |= MachineWorkMode.AllowDirectAccess;

Using DirectAccess

For demo how to use DirectAccess, we define a class in .Net:

public class User 
{
  private string nickname = "no name";

  public string Nickname
  {
    get { return nickname; }
    set { nickname = value; }
  }

  public void Hello()
  {
    MessageBox.Show(string.Format("Hello {0}!", nickname));
  }
}

This User class contains a public property Nickname and a public method Hello, we trying to access this property and call the function in script.

In this demo we create the instance of User class in .Net and put it into script context: (instance can also be created in script, see import keyword.

srm.SetGlobalVariable("guest", new User());

An object named guest was be created and added into script, so now we can use this object:

guest.nickname = 'player1';
guest.hello();

When this script executed, a windows message box will be display.

Hello player1!