feat: extract log API to console
This commit is contained in:
parent
56ae3a85a6
commit
304665904f
@ -711,14 +711,14 @@ public class Values {
|
|||||||
res.append("{\n");
|
res.append("{\n");
|
||||||
|
|
||||||
for (var el : obj.values.entrySet()) {
|
for (var el : obj.values.entrySet()) {
|
||||||
for (int i = 0; i < tab + 1; i++) System.out.print(" ");
|
for (int i = 0; i < tab + 1; i++) res.append(" ");
|
||||||
res.append(toReadable(ctx, el.getKey(), passed, tab + 1));
|
res.append(toReadable(ctx, el.getKey(), passed, tab + 1));
|
||||||
res.append(": ");
|
res.append(": ");
|
||||||
res.append(toReadable(ctx, el.getValue(), passed, tab + 1));
|
res.append(toReadable(ctx, el.getValue(), passed, tab + 1));
|
||||||
res.append(",\n");
|
res.append(",\n");
|
||||||
}
|
}
|
||||||
for (var el : obj.properties.entrySet()) {
|
for (var el : obj.properties.entrySet()) {
|
||||||
for (int i = 0; i < tab + 1; i++) System.out.print(" ");
|
for (int i = 0; i < tab + 1; i++) res.append(" ");
|
||||||
res.append(toReadable(ctx, el.getKey(), passed, tab + 1));
|
res.append(toReadable(ctx, el.getKey(), passed, tab + 1));
|
||||||
res.append(": [prop],\n");
|
res.append(": [prop],\n");
|
||||||
}
|
}
|
||||||
|
36
src/java/me/topchetoeu/jscript/lib/ConsoleLib.java
Normal file
36
src/java/me/topchetoeu/jscript/lib/ConsoleLib.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package me.topchetoeu.jscript.lib;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import me.topchetoeu.jscript.core.engine.values.Values;
|
||||||
|
import me.topchetoeu.jscript.utils.filesystem.FilesystemException;
|
||||||
|
import me.topchetoeu.jscript.utils.filesystem.FilesystemException.FSCode;
|
||||||
|
import me.topchetoeu.jscript.utils.interop.Arguments;
|
||||||
|
import me.topchetoeu.jscript.utils.interop.Expose;
|
||||||
|
import me.topchetoeu.jscript.utils.interop.WrapperName;
|
||||||
|
|
||||||
|
@WrapperName("Console")
|
||||||
|
public class ConsoleLib {
|
||||||
|
private final OutputStream stream;
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
public void __log(Arguments args) {
|
||||||
|
try {
|
||||||
|
var first = true;
|
||||||
|
for (var el : args.args) {
|
||||||
|
if (!first) stream.write(" ".getBytes());
|
||||||
|
first = false;
|
||||||
|
stream.write(Values.toReadable(args.ctx, el).getBytes());
|
||||||
|
}
|
||||||
|
stream.write((byte)'\n');
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new FilesystemException("stdout", FSCode.NO_PERMISSIONS_RW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConsoleLib(OutputStream stream) {
|
||||||
|
this.stream = stream;
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,7 @@
|
|||||||
package me.topchetoeu.jscript.lib;
|
package me.topchetoeu.jscript.lib;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.common.Reading;
|
|
||||||
import me.topchetoeu.jscript.core.engine.Context;
|
import me.topchetoeu.jscript.core.engine.Context;
|
||||||
import me.topchetoeu.jscript.core.engine.Environment;
|
import me.topchetoeu.jscript.core.engine.Environment;
|
||||||
import me.topchetoeu.jscript.core.engine.scope.GlobalScope;
|
import me.topchetoeu.jscript.core.engine.scope.GlobalScope;
|
||||||
@ -34,27 +32,6 @@ public class Internals {
|
|||||||
else throw EngineException.ofError("Modules are not supported.");
|
else throw EngineException.ofError("Modules are not supported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Expose(target = ExposeTarget.STATIC)
|
|
||||||
public static Object __log(Arguments args) {
|
|
||||||
for (var arg : args.args) {
|
|
||||||
Values.printValue(args.ctx, arg);
|
|
||||||
System.out.print(" ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
return args.get(0);
|
|
||||||
}
|
|
||||||
@Expose(target = ExposeTarget.STATIC)
|
|
||||||
public static String __readline() {
|
|
||||||
try {
|
|
||||||
return Reading.readline();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Expose(target = ExposeTarget.STATIC)
|
@Expose(target = ExposeTarget.STATIC)
|
||||||
public static Thread __setTimeout(Arguments args) {
|
public static Thread __setTimeout(Arguments args) {
|
||||||
var func = args.convert(0, FunctionValue.class);
|
var func = args.convert(0, FunctionValue.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user