-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add global and value-local functions
- Loading branch information
1 parent
8104dc1
commit 7e3f118
Showing
7 changed files
with
163 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/org/cyclops/integratedscripting/evaluate/ScriptHelpers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.cyclops.integratedscripting.evaluate; | ||
|
||
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException; | ||
import org.cyclops.integrateddynamics.api.evaluate.operator.IOperator; | ||
import org.cyclops.integrateddynamics.core.evaluate.operator.Operators; | ||
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeOperator; | ||
import org.cyclops.integratedscripting.evaluate.translation.ValueTranslators; | ||
import org.graalvm.polyglot.Context; | ||
import org.graalvm.polyglot.Engine; | ||
import org.graalvm.polyglot.Value; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @author rubensworks | ||
*/ | ||
public class ScriptHelpers { | ||
|
||
public static Context createBaseContext() { | ||
Engine engine = Engine | ||
.newBuilder() | ||
.option("engine.WarnInterpreterOnly", "false") | ||
.build(); | ||
return Context | ||
.newBuilder() | ||
.engine(engine) | ||
.allowAllAccess(true) | ||
.build(); | ||
} | ||
|
||
public static Context createPopulatedContext() throws EvaluationException { | ||
Context context = createBaseContext(); | ||
|
||
// Create idContext field with ops | ||
Value idContext = context.eval("js", "new Object()"); | ||
Value ops = context.eval("js", "new Object()"); | ||
for (Map.Entry<String, IOperator> entry : Operators.REGISTRY.getGlobalInteractOperators().entrySet()) { | ||
ops.putMember(entry.getKey(), ValueTranslators.REGISTRY.translateToGraal(context, ValueTypeOperator.ValueOperator.of(entry.getValue()))); | ||
} | ||
idContext.putMember("ops", ops); | ||
context.getBindings("js").putMember("idContext", idContext); | ||
|
||
return context; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters