-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed to using ScriptObjectMirror again for running functions.
Caused errors with some mods that defined their returns oddly. Next breaking version should change things to return a Function directly.
- Loading branch information
Showing
5 changed files
with
33 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#occupational hazards | ||
/logs/ | ||
/out/ | ||
/repo/ | ||
|
||
#eclipse | ||
**/bin | ||
|
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
9 changes: 9 additions & 0 deletions
9
src/java15/java/net/minecraftforge/coremod/NashornFactory.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 |
---|---|---|
@@ -1,11 +1,20 @@ | ||
package net.minecraftforge.coremod; | ||
|
||
import java.util.function.Function; | ||
|
||
import javax.script.Bindings; | ||
import javax.script.ScriptEngine; | ||
|
||
import org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory; | ||
import org.openjdk.nashorn.api.scripting.ScriptObjectMirror; | ||
|
||
class NashornFactory { | ||
static ScriptEngine createEngine() { | ||
return new NashornScriptEngineFactory().getScriptEngine(CoreModEngine::checkClass); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
static <A,R> Function<A,R> getFunction(Bindings obj) { | ||
return a -> (R)((ScriptObjectMirror)obj).call(obj, a); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
package net.minecraftforge.coremod; | ||
|
||
import java.util.function.Function; | ||
|
||
import javax.script.Bindings; | ||
import javax.script.ScriptEngine; | ||
|
||
import jdk.nashorn.api.scripting.NashornScriptEngineFactory; | ||
import jdk.nashorn.api.scripting.ScriptObjectMirror; | ||
|
||
class NashornFactory { | ||
static ScriptEngine createEngine() { | ||
return new NashornScriptEngineFactory().getScriptEngine(CoreModEngine::checkClass); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
static <A,R> Function<A,R> getFunction(Bindings obj) { | ||
return a -> (R)((ScriptObjectMirror)obj).call(obj, a); | ||
} | ||
} |
997eab2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious what the problem with the other way was?
997eab2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take this for example:
The eval form of the cast would be:
Which is executed on the root context, and that'd fail with unknown reference ASMAPI.
Either way, this bypasses all that and is only a slight reference to Nashorn. It would be nice if in the future we ask the coremod itself to return a java.util.Function reference, and not a js function.