-
Notifications
You must be signed in to change notification settings - Fork 35
DirectAccess
ReoScript supports directly to access .Net object in script. The following behavior are available:
- Improt .Net classes and namespaces
- Create instance of .Net class
- Access property of .Net instance
- Bind event of .Net instance
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;
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!