refactor: generalize Reading class
This commit is contained in:
parent
c36a0db860
commit
e372941e99
@ -60,7 +60,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
for (var i = 0; ; i++) {
|
for (var i = 0; ; i++) {
|
||||||
try {
|
try {
|
||||||
var raw = Reading.read();
|
var raw = Reading.readline();
|
||||||
|
|
||||||
if (raw == null) break;
|
if (raw == null) break;
|
||||||
var res = engine.pushMsg(
|
var res = engine.pushMsg(
|
||||||
@ -136,16 +136,16 @@ public class Main {
|
|||||||
engine.pushMsg(
|
engine.pushMsg(
|
||||||
false, tsEnv,
|
false, tsEnv,
|
||||||
new Filename("jscript", "ts.js"),
|
new Filename("jscript", "ts.js"),
|
||||||
Reading.resourceToString("js/ts.js"), null
|
Reading.resourceToString("assets/js/ts.js"), null
|
||||||
).await();
|
).await();
|
||||||
System.out.println("Loaded typescript!");
|
System.out.println("Loaded typescript!");
|
||||||
|
|
||||||
var typescript = tsEnv.global.get(new Context(engine, bsEnv), "ts");
|
var typescript = tsEnv.global.get(new Context(engine, bsEnv), "ts");
|
||||||
var libs = new ArrayValue(null, Reading.resourceToString("js/lib.d.ts"));
|
var libs = new ArrayValue(null, Reading.resourceToString("assets/js/lib.d.ts"));
|
||||||
|
|
||||||
engine.pushMsg(
|
engine.pushMsg(
|
||||||
false, bsEnv,
|
false, bsEnv,
|
||||||
new Filename("jscript", "bootstrap.js"), Reading.resourceToString("js/bootstrap.js"), null,
|
new Filename("jscript", "bootstrap.js"), Reading.resourceToString("assets/js/bootstrap.js"), null,
|
||||||
typescript, new EnvironmentLib(environment), libs
|
typescript, new EnvironmentLib(environment), libs
|
||||||
).await();
|
).await();
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import me.topchetoeu.jscript.exceptions.UncheckedException;
|
|||||||
public class Reading {
|
public class Reading {
|
||||||
private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
|
||||||
public static synchronized String read() throws IOException {
|
public static synchronized String readline() throws IOException {
|
||||||
return reader.readLine();
|
return reader.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ public class Reading {
|
|||||||
catch (Throwable e) { throw new UncheckedException(e); }
|
catch (Throwable e) { throw new UncheckedException(e); }
|
||||||
}
|
}
|
||||||
public static InputStream resourceToStream(String name) {
|
public static InputStream resourceToStream(String name) {
|
||||||
return Reading.class.getResourceAsStream("/assets/" + name);
|
return Reading.class.getResourceAsStream("/" + name);
|
||||||
}
|
}
|
||||||
public static String resourceToString(String name) {
|
public static String resourceToString(String name) {
|
||||||
return streamToString(resourceToStream(name));
|
return streamToString(resourceToStream(name));
|
||||||
|
@ -231,9 +231,9 @@ public class DebugServer {
|
|||||||
|
|
||||||
public DebugServer() {
|
public DebugServer() {
|
||||||
try {
|
try {
|
||||||
this.favicon = Reading.resourceToStream("debugger/favicon.png").readAllBytes();
|
this.favicon = Reading.resourceToStream("assets/debugger/favicon.png").readAllBytes();
|
||||||
this.protocol = Reading.resourceToStream("debugger/protocol.json").readAllBytes();
|
this.protocol = Reading.resourceToStream("assets/debugger/protocol.json").readAllBytes();
|
||||||
this.index = Reading.resourceToString("debugger/index.html")
|
this.index = Reading.resourceToString("assets/debugger/index.html")
|
||||||
.replace("${NAME}", Metadata.name())
|
.replace("${NAME}", Metadata.name())
|
||||||
.replace("${VERSION}", Metadata.version())
|
.replace("${VERSION}", Metadata.version())
|
||||||
.replace("${AUTHOR}", Metadata.author())
|
.replace("${AUTHOR}", Metadata.author())
|
||||||
|
@ -40,7 +40,7 @@ public class Internals {
|
|||||||
}
|
}
|
||||||
@Native public static String readline(Context ctx) {
|
@Native public static String readline(Context ctx) {
|
||||||
try {
|
try {
|
||||||
return Reading.read();
|
return Reading.readline();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user