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

import keyword

import keyword used to import other resources into current script context. This keyword is not compliant with ECMAScript standard. The following resources are available to be imported:
  1. Import other script files into current script context
  2. Import .NET types
  3. Import .NET namespaces

Import other script files

common.reo:
function hash_password(pwd) {
  return hash(pwd);
}

main.reo:
import common.reo;

function login(usr, pwd) {
  if (hash_password(pwd) != ...) {       // hash_password defined in common.js
    return false;
  } else {
    return true;
  }
}

Note: resources to be imported by this keyword with a full name of file path which can only be imported once.

Relative path to find file

Resources can be imported by specifying a relative path, the full path will be evaluated by workpath variable of ScriptRunningMachine. (Learn more about WorkPath)

Import .NET types or namespaces into script context

use import keyboard can import .NET types and namespaces into current script context. Types imported into script context can be instanced by script as function call.
// import .NET class
import System.Windows.Forms.Form;    // import type
import System.Drawing.*;             // import namespace (all types belonging to this namespace will be imported)

Then an instance of Form can be created as below:
var f = new Form();    // initialize instance of Form (.NET Type constructor will be invoked)
f.show();              // show window by call .NET method

Note: Since allowing script to import any .NET types is not safety in some cases, there is possible to disable this feature by setting the workmode of ScriptRunningMachine. (Learn more about workmode)

Learn more about CLR Type Importing.

Last edited Jan 17, 2014 at 2:04 PM by unvell, version 7