refactor: generalize Reading class

This commit is contained in:
TopchetoEU 2023-12-27 20:18:41 +02:00
parent c36a0db860
commit e372941e99
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
4 changed files with 10 additions and 10 deletions

View File

@ -60,7 +60,7 @@ public class Main {
}
for (var i = 0; ; i++) {
try {
var raw = Reading.read();
var raw = Reading.readline();
if (raw == null) break;
var res = engine.pushMsg(
@ -136,16 +136,16 @@ public class Main {
engine.pushMsg(
false, tsEnv,
new Filename("jscript", "ts.js"),
Reading.resourceToString("js/ts.js"), null
Reading.resourceToString("assets/js/ts.js"), null
).await();
System.out.println("Loaded typescript!");
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(
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
).await();
}

View File

@ -10,7 +10,7 @@ import me.topchetoeu.jscript.exceptions.UncheckedException;
public class Reading {
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();
}
@ -19,7 +19,7 @@ public class Reading {
catch (Throwable e) { throw new UncheckedException(e); }
}
public static InputStream resourceToStream(String name) {
return Reading.class.getResourceAsStream("/assets/" + name);
return Reading.class.getResourceAsStream("/" + name);
}
public static String resourceToString(String name) {
return streamToString(resourceToStream(name));

View File

@ -231,9 +231,9 @@ public class DebugServer {
public DebugServer() {
try {
this.favicon = Reading.resourceToStream("debugger/favicon.png").readAllBytes();
this.protocol = Reading.resourceToStream("debugger/protocol.json").readAllBytes();
this.index = Reading.resourceToString("debugger/index.html")
this.favicon = Reading.resourceToStream("assets/debugger/favicon.png").readAllBytes();
this.protocol = Reading.resourceToStream("assets/debugger/protocol.json").readAllBytes();
this.index = Reading.resourceToString("assets/debugger/index.html")
.replace("${NAME}", Metadata.name())
.replace("${VERSION}", Metadata.version())
.replace("${AUTHOR}", Metadata.author())

View File

@ -40,7 +40,7 @@ public class Internals {
}
@Native public static String readline(Context ctx) {
try {
return Reading.read();
return Reading.readline();
}
catch (IOException e) {
e.printStackTrace();