@ -13,12 +13,14 @@ import java.nio.file.Paths;
|
||||
* @author 喵♂呜 Created on 2017/10/25 21:01.
|
||||
*/
|
||||
public class ScriptEngine {
|
||||
private final String root;
|
||||
private final ClassLoader loader;
|
||||
private final Object logger;
|
||||
private final String root;
|
||||
private final Base base;
|
||||
private MiaoScriptEngine engine;
|
||||
|
||||
public ScriptEngine(String root, Object logger, Object instance) {
|
||||
this.loader = Thread.currentThread().getContextClassLoader();
|
||||
this.root = root;
|
||||
this.logger = logger;
|
||||
this.base = new Base(instance);
|
||||
@ -38,6 +40,8 @@ public class ScriptEngine {
|
||||
@SneakyThrows
|
||||
public void enableEngine() {
|
||||
createEngine();
|
||||
ClassLoader originLoader = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(this.loader);
|
||||
Path bios = Paths.get(root, "bios.js");
|
||||
// 如果存在自定义bios就加载自定义的
|
||||
if (Files.exists(bios)) {
|
||||
@ -46,6 +50,7 @@ public class ScriptEngine {
|
||||
this.engine.eval("load('classpath:bios.js')");
|
||||
}
|
||||
engine.invokeFunction("boot", root, logger);
|
||||
Thread.currentThread().setContextClassLoader(originLoader);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
|
Reference in New Issue
Block a user