Skip to content
Jing edited this page Jul 25, 2019 · 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 by standard ECMAScript/JavaScript or others interpreter. Currently the import keyword can do the following actions:

  1. Import other script file
  2. Import .NET classes
  3. Import .NET 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 using import keyword:

    import System.Windows.Forms.Form;    // import .NET Type
    import System.Drawing.*;             // import .NET 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 

See more about CLR Type Importing.