-
Notifications
You must be signed in to change notification settings - Fork 1
Scripting API
The Console is built on top of Nashorn which already provides multiple things, but most of all, it connects with Java classes very well. Besides Nashorn, The Console itself provides few functions available to use across both single-file scripts and modules.
args.length
args[0], args[1], ...
Utils.audioFilePlayer.play(filePath)
Utils.exec(filePath)
Utils.execAsync(filePath)
Utils.getClassName(object)
Utils.openUrl(encodeURI(someUrl))
Utils.requestUrl(url) //HTTP GET
Utils.completePath(absolutePath)
console.log(text)
console.log(text, color)
console.error(text)
console.clear()
console.hide()
console.window
assert(bool, string)
assertInfo(bool, string)
JavaClass(className) // Java: Class.forName(className);
System // Java: System.class
Sources for globals:
-
Utils
is placed in JsUtilsProvider.xtend -
console
is ConsoleProxy.xtend - whole file script is lanched by ConsoleContext.xtend#runJs()
- Java->JavaScript bindings are made in JavaScriptEnvironment#ctor
Every script can store it's configuration or whatever. To see some examples go see filesystem
.
-
Get your storage:
Storage = Storage.getGlobalStorage("myscript")
-
Get variable
var path = Storage.get("path") console.log(path)
-
Overwrite variable and save Storage
var newPath = ... Storage.set("path", newPath) Storage.save()
You can assert
whatever you like, e.g. script arguments.
When first argument of assert
/assertInfo
is not true, it stops whole scripts and displays given text to the console:
-
red text:
assert(args.length == 0, "Please, no args.")
-
white text:
assertInfo(args.length == 0, "Please, no args.")
https://gist.github.com/WebReflection/9627010
https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/api.html