@Override
public void run() {
ScriptEngine engine = loader.getScriptEngine();
try {
// create bindings
Bindings bindings = engine.createBindings();
// provide an export for this scripts attributes
bindings.put("loader", loader);
bindings.put("registry", terminableRegistry);
bindings.put("logger", logger);
// the path of the script file (current working directory)
bindings.put("cwd", path.normalize().toString().replace("\\", "/"));
// the root scripts directory
bindings.put("rsd", loader.getDirectory().normalize().toString().replace("\\", "/") + "/");
// function to depend on another script
bindings.put("depend", (Consumer<String>) this::depend);
// append the global helper bindings to this instance
systemBindings.appendTo(bindings);
// create a new script context, and attach our bindings
ScriptContext context = new SimpleScriptContext();
context.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
// evaluate the header
engine.eval(systemBindings.getPlugin().getScriptHeader(), context);
// resolve the load path, relative to the loader directory.
Path loadPath = loader.getDirectory().normalize().resolve(path);
engine.eval("__load(\"" + loadPath.toString().replace("\\", "/") + "\");", context);
} catch (Throwable t) {
t.printStackTrace();
}
}
HelperScript.java 文件源码
java
阅读 16
收藏 0
点赞 0
评论 0
项目:helper
作者:
评论列表
文章目录