Merge branch 'master' into future

This commit is contained in:
gnembon committed 2021-11-27 22:22:38 +01:00
commit 3312c00ee8
7 files changed
+40 -10

No files matched your search

@@ -12,6 +12,7 @@ import carpet.script.bundled.BundledModule;
import carpet.CarpetServer;
import carpet.script.bundled.FileModule;
import carpet.script.bundled.Module;
import carpet.script.exception.ExpressionException;
import carpet.script.language.Arithmetic;
import carpet.script.language.ControlFlow;
import carpet.script.language.DataStructures;
@@ -437,6 +438,7 @@ public class CarpetScriptServer
public static void parseFunctionClasses()
{
ExpressionException.prepareForDoom(); // see fc-#1172
// Language
AnnotationParser.parseFunctionClass(Arithmetic.class);
AnnotationParser.parseFunctionClass(ControlFlow.class);
@@ -683,6 +683,7 @@ public class Auxiliary {
expression.addContextFunction("game_tick", -1, (c, t, lv) -> {
CarpetContext cc = (CarpetContext)c;
ServerCommandSource s = cc.s;
if (CarpetServer.scriptServer == null) return Value.NULL;
if (!s.getServer().isOnThread()) throw new InternalExpressionException("Unable to run ticks from threads");
if (CarpetServer.scriptServer.tickDepth > 16) throw new InternalExpressionException("'game_tick' function caused other 'game_tick' functions to run. You should not allow that.");
try
@@ -710,9 +711,10 @@ public class Auxiliary {
}
finally
{
CarpetServer.scriptServer.tickDepth --;
if (CarpetServer.scriptServer != null)
CarpetServer.scriptServer.tickDepth --;
}
if(CarpetServer.scriptServer.stopAll)
if(CarpetServer.scriptServer != null && CarpetServer.scriptServer.stopAll)
throw new ExitStatement(Value.NULL);
return Value.TRUE;
});
@@ -5,6 +5,7 @@ import carpet.script.Expression;
import carpet.script.Fluff;
import carpet.script.Tokenizer;
import carpet.script.value.FunctionValue;
import carpet.utils.Messenger;
import java.util.ArrayList;
import java.util.Collections;
@@ -19,6 +20,9 @@ public class ExpressionException extends RuntimeException implements ResolvedExc
public final List<FunctionValue> stack = new ArrayList<>();
private final Supplier<String> lazyMessage;
private String cachedMessage = null;
public static void prepareForDoom(){
Messenger.c("foo bar");
}
public ExpressionException(Context c, Expression e, String message)
{
@@ -29,6 +29,10 @@ public class Arithmetic {
}
return new NumericValue(factorial);
}
else if (number > 170)
{
return NumericValue.of(Double.MAX_VALUE);
}
// values over 21 will exceed long limits
double factorial = 1.0;
for (int i = 1; i <= number; i++)