Files
dev/script/test/tstrun.js
2018-04-17 12:05:48 +02:00

32 lines
926 B
JavaScript
Executable File

function run(script_name, args) {
/*
Run script: can be absolute path, relative, or short name to be search in the path.
Args:
args(Dict ot Array): gobal variables set to the script(if dict), or argv varialble (if array).
Returns:
The script return value
*/
var script = get_context().scriptManager.library.resolveFile(script_name)
var file = script!=null ? new File(script) : null
if ((file == null) || ( ! file.exists())) throw "Invalid script: " + script_name
get_context().startScriptExecution(args)
if (is_defined(args) && (args!=null)){
if (is_array(args)){
argv = args
} else {
for (var key in args) {
eval(key+"="+args[key])
}
}
}
//eval(new String(Files.readAllBytes(file.toPath())))
//get_context().scriptManager.interpreter.evalFile(script);
load(script)
}