parent
9bb67410ac
commit
e71bd2a0cb
4
pom.xml
4
pom.xml
|
@ -2,11 +2,11 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>MiaoScript</artifactId>
|
<artifactId>MiaoScript</artifactId>
|
||||||
<version>0.7.3</version>
|
<version>0.7.5</version>
|
||||||
<developers>
|
<developers>
|
||||||
<developer>
|
<developer>
|
||||||
<id>502647092</id>
|
<id>502647092</id>
|
||||||
<name>喵♂呜</name>
|
<name>MiaoWoo</name>
|
||||||
<email>admin@yumc.pw</email>
|
<email>admin@yumc.pw</email>
|
||||||
<url>http://www.yumc.pw</url>
|
<url>http://www.yumc.pw</url>
|
||||||
</developer>
|
</developer>
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package pw.yumc.MiaoScript;
|
package pw.yumc.MiaoScript;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
|
import javax.script.ScriptEngineManager;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import javax.script.ScriptEngineManager;
|
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
*
|
*
|
||||||
|
@ -27,21 +26,26 @@ public class ScriptEngine {
|
||||||
this.manager = new ScriptEngineManager();
|
this.manager = new ScriptEngineManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
public synchronized MiaoScriptEngine createEngine() {
|
||||||
public synchronized void enableEngine() {
|
|
||||||
if (this.engine == null) {
|
if (this.engine == null) {
|
||||||
this.engine = new MiaoScriptEngine(manager, "nashorn");
|
this.engine = new MiaoScriptEngine(manager, "nashorn");
|
||||||
this.engine.put("base", this.base);
|
this.engine.put("base", this.base);
|
||||||
this.engine.put("ScriptEngineContextHolder", this);
|
this.engine.put("ScriptEngineContextHolder", this);
|
||||||
Path bios = Paths.get(root, "bios.js");
|
|
||||||
// 如果存在自定义bios就加载自定义的
|
|
||||||
if (Files.exists(bios)) {
|
|
||||||
this.engine.eval("load('" + bios.toFile().getCanonicalPath() + "')");
|
|
||||||
} else {
|
|
||||||
this.engine.eval("load('classpath:bios.js')");
|
|
||||||
}
|
|
||||||
engine.invokeFunction("boot", root, logger);
|
|
||||||
}
|
}
|
||||||
|
return this.engine;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public void enableEngine() {
|
||||||
|
createEngine();
|
||||||
|
Path bios = Paths.get(root, "bios.js");
|
||||||
|
// 如果存在自定义bios就加载自定义的
|
||||||
|
if (Files.exists(bios)) {
|
||||||
|
this.engine.eval("load('" + bios.toFile().getCanonicalPath() + "')");
|
||||||
|
} else {
|
||||||
|
this.engine.eval("load('classpath:bios.js')");
|
||||||
|
}
|
||||||
|
engine.invokeFunction("boot", root, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
|
|
Loading…
Reference in New Issue