Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<PartTypePanelDisplay, PartTypePanelDisplay.State> 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);
Expand Down
Loading