diff --git a/src/main/java/org/cyclops/integratedscripting/core/packageddependencies/PackagedDependenciesLoader.java b/src/main/java/org/cyclops/integratedscripting/core/packageddependencies/PackagedDependenciesLoader.java index c95aa35b1..13858d1af 100644 --- a/src/main/java/org/cyclops/integratedscripting/core/packageddependencies/PackagedDependenciesLoader.java +++ b/src/main/java/org/cyclops/integratedscripting/core/packageddependencies/PackagedDependenciesLoader.java @@ -70,6 +70,11 @@ public static void load() throws IOException { Context.Builder build = Context.newBuilder("js"); Context con = build.build(); con.eval("js", "console.log('graaljs has been pre-loaded.')"); + // Force-initialize TRegex here as well. + // Its static loggers resolve the 'regex' language id via the thread context classloader, + // which only points to Graal within this block. + // Initializing it later (on a server thread) fails permanently for the whole JVM session. + con.eval("js", "/graaljs/.test('graaljs')"); con.close(); } finally { Thread.currentThread().setContextClassLoader(p); diff --git a/src/main/java/org/cyclops/integratedscripting/gametest/GameTestsScripts.java b/src/main/java/org/cyclops/integratedscripting/gametest/GameTestsScripts.java index f33feb641..b7c2186e9 100644 --- a/src/main/java/org/cyclops/integratedscripting/gametest/GameTestsScripts.java +++ b/src/main/java/org/cyclops/integratedscripting/gametest/GameTestsScripts.java @@ -15,6 +15,7 @@ import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeItemStack; import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeBoolean; import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeInteger; +import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeString; import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes; import org.cyclops.integrateddynamics.part.PartTypePanelDisplay; import org.cyclops.integratedscripting.Reference; @@ -118,6 +119,37 @@ public void testScriptsDisplayScriptOnItem(GameTestHelper helper) { }); } + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) + public void testScriptsDisplayScriptRegex(GameTestHelper helper) { + GameTestHelpersIntegratedScripting.NetworkPositions positions = createBasicNetwork(helper, POS); + + // Write script + ScriptingNetworkHelpers.getScriptingData().setScript(positions.diskId(), Path.of("script0.js"), "function abc(a) { return /^aether:.+_gloves/.test(a); }", IScriptingData.ChangeLocation.MEMORY); + + // Create variable from script + ItemStack variableScript = createVariableForScript(helper.getLevel(), positions.diskId(), Path.of("script0.js"), "abc"); + + // Create constants as input to the script's function + ItemStack variableConst1 = createVariableForValue(helper.getLevel(), ValueTypes.STRING, ValueTypeString.ValueString.of("aether:leather_gloves")); + + // Insert all variables into the variable store + positions.variableStore().getInventory().setItem(0, variableScript); + positions.variableStore().getInventory().setItem(1, variableConst1); + + // Create variable card for applying the function + ItemStack variableApplied = createVariableForOperator(helper.getLevel(), Operators.OPERATOR_APPLY, new int[]{ + getVariableFacade(helper.getLevel(), variableScript).getId(), + getVariableFacade(helper.getLevel(), variableConst1).getId(), + }); + + // Place variable in display + Pair partAndState = placeVariableInDisplayPanel(helper.getLevel(), positions.displayPanel(), variableApplied); + + helper.succeedWhen(() -> { + assertValueEqual(partAndState.getRight().getDisplayValue(), ValueTypeBoolean.ValueBoolean.of(true)); + }); + } + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) public void testScriptsDisplayScriptInfiniteLoop(GameTestHelper helper) { GameTestHelpersIntegratedScripting.NetworkPositions positions = createBasicNetwork(helper, POS);