-
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 in standard ECMAScript/JavaScript or others interpreter. Currently the import keyword functions on following features:
- Import other script file into current script context
- Import .Net class and use it in script
- Import .Net namespace and use the all of classes from the 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 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