Skip to content

Commit 7aeedba

Browse files
committed
Move print delegation.
1 parent 65b14fe commit 7aeedba

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/main/java/org/byteskript/skript/runtime/internal/ExtractedSyntaxCalls.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ public static void runOnMainThread(final Instruction<?> runnable) throws Throwab
9999
}
100100

101101
public static void print(Object object) throws Throwable {
102-
final Skript skript = findInstance();
103-
skript.println(object);
102+
final Thread current = Thread.currentThread();
103+
if (current instanceof ScriptThread thread) thread.println(object);
104+
else System.out.println(object);
104105
}
105106

106107
public static String readSystemInput() throws Throwable {

src/main/java/org/byteskript/skript/runtime/threading/ScriptThread.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.byteskript.skript.runtime.internal.CompiledScript;
1212
import org.byteskript.skript.runtime.internal.ThreadVariableMap;
1313

14+
import java.io.PrintWriter;
15+
1416
/**
1517
* A script thread.
1618
* All scripts should run on script threads.
@@ -29,11 +31,21 @@ public class ScriptThread extends Thread {
2931
public final Skript skript;
3032
public Class<? extends CompiledScript> initiator;
3133
public Event event;
34+
private PrintWriter writer;
3235

3336
public ScriptThread(final Skript skript, final OperationController controller, ThreadGroup group, Runnable target, String name, long stackSize, boolean inheritThreadLocals) {
3437
super(group, target, name, stackSize, inheritThreadLocals);
3538
this.skript = skript;
3639
this.controller = controller;
3740
this.queue = controller.queue;
3841
}
42+
43+
public void println(Object object) {
44+
if (writer != null) writer.println(object);
45+
else skript.println(object);
46+
}
47+
48+
public void setWriter(PrintWriter writer) {
49+
this.writer = writer;
50+
}
3951
}

src/main/java/org/byteskript/skript/runtime/type/OperatorFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public boolean reversible() {
2929
};
3030
}
3131

32-
Object union(A first, B second) throws Throwable;
33-
3432
default Object union2(B first, A second) throws Throwable {
3533
return this.union(second, first);
3634
}
3735

36+
Object union(A first, B second) throws Throwable;
37+
3838
default boolean reversible() {
3939
return true;
4040
}

0 commit comments

Comments
 (0)