Pack Imports.

This commit is contained in:
Stephen Chung
2020-11-01 23:42:00 +08:00
parent 717e8e7eee
commit b07a2aa79c
3 changed files with 73 additions and 22 deletions

View File

@@ -25,6 +25,14 @@ import "crypto_init"; // run the script file 'crypto_init.rhai' withou
import "crypto" as lock; // run the script file 'crypto.rhai' and import it as a module named 'lock'
const SECRET_NUMBER = 42;
let mod_file = "crypto_" + SECRET_NUMBER;
import mod_file as my_mod; // load the script file "crypto_42.rhai" and import it as a module named 'my_mod'
// notice that module path names can be dynamically constructed!
// any expression that evaluates to a string is acceptable after the 'import' keyword
lock::encrypt(secret); // use functions defined under the module via '::'
lock::hash::sha256(key); // sub-modules are also supported