Skip to content

Commit

Permalink
Move print delegation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Moderocky committed Sep 20, 2022
1 parent 65b14fe commit 7aeedba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ public static void runOnMainThread(final Instruction<?> runnable) throws Throwab
}

public static void print(Object object) throws Throwable {
final Skript skript = findInstance();
skript.println(object);
final Thread current = Thread.currentThread();
if (current instanceof ScriptThread thread) thread.println(object);
else System.out.println(object);
}

public static String readSystemInput() throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.byteskript.skript.runtime.internal.CompiledScript;
import org.byteskript.skript.runtime.internal.ThreadVariableMap;

import java.io.PrintWriter;

/**
* A script thread.
* All scripts should run on script threads.
Expand All @@ -29,11 +31,21 @@ public class ScriptThread extends Thread {
public final Skript skript;
public Class<? extends CompiledScript> initiator;
public Event event;
private PrintWriter writer;

public ScriptThread(final Skript skript, final OperationController controller, ThreadGroup group, Runnable target, String name, long stackSize, boolean inheritThreadLocals) {
super(group, target, name, stackSize, inheritThreadLocals);
this.skript = skript;
this.controller = controller;
this.queue = controller.queue;
}

public void println(Object object) {
if (writer != null) writer.println(object);
else skript.println(object);
}

public void setWriter(PrintWriter writer) {
this.writer = writer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public boolean reversible() {
};
}

Object union(A first, B second) throws Throwable;

default Object union2(B first, A second) throws Throwable {
return this.union(second, first);
}

Object union(A first, B second) throws Throwable;

default boolean reversible() {
return true;
}
Expand Down

0 comments on commit 7aeedba

Please sign in to comment.