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

The import keyword is ReoScript own syntax to import external source such as .Net class or other script files. It may not be supported in standard ECMAScript/JavaScript or others interpreter. Currently the import keyword functions on following features:

  1. Import other script file into current script context
  2. Import .Net class and use it in script
  3. Import .Net namespace and use the all of classes from the namespace

Import other script files

In HTML and JavaScript, we can use the <script/> to import a JavaScript file.

<script language="JavaScript" src="js/common.js"/>     // in HTML

But ReoScript can be executed with plain script and there is no other files like HTML needed. Any script file firstly to be executed could uses import keyword to import other script files:

common.js:

function hash_password(pwd) {
  return hash(pwd);
}

main.js:

import common.js;

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

In addition, import keyword will check whether a file has been already imported by file's full path. So we do not have a problem with recursive import.

Relative path to find file

The script file with relative path could be specified when using import keyword. ReoScript convert any relative path to full path with workpath of ScriptRunningMachine. (See more about workpath)

Import .Net class or namespace into script

.Net class or namespace can be used in script directly once they be imported using import keyword:

// import .Net class
import System.Windows.Forms.Form;    // import Type
import System.Drawing.*;             // import Namespace

Then an instance of Form can be used as below:

var f = new Form();    // Form is .Net class
f.show();              // show is .Net method of Form