-
Notifications
You must be signed in to change notification settings - Fork 35
import Keyword
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:
- Import other script file
- Import .NET classes
- Import .NET namespace
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.
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)
.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.