-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
96 additions
and
91 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
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
5 changes: 2 additions & 3 deletions
5
...awa12/fixRtm/scripting/FIXScriptEngine.kt → ...m/scripting/rhino/FIXRhinoScriptEngine.kt
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
50 changes: 50 additions & 0 deletions
50
src/main/java/com/anatawa12/fixRtm/scripting/rhino/ImportScriptRhinoFunctionImpl.kt
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,50 @@ | ||
package com.anatawa12.fixRtm.scripting.rhino | ||
|
||
import com.anatawa12.fixRtm.io.FIXFileLoader | ||
import com.anatawa12.fixRtm.io.FIXModelPack | ||
import com.anatawa12.fixRtm.scripting.ScriptImporter | ||
import net.minecraft.util.ResourceLocation | ||
import org.mozilla.javascript.* | ||
|
||
|
||
object ImportScriptRhinoFunctionImpl : BaseFunction() { | ||
fun getScript(name: String): Script { | ||
val resourceLocation = ResourceLocation(name) | ||
val resource = FIXFileLoader.getResource(resourceLocation) | ||
val script = resource.inputStream.reader().use { it.readText() } | ||
return makeScript(resourceLocation, script, resource.pack) | ||
} | ||
|
||
fun makeScript(location: ResourceLocation, script: String, pack: FIXModelPack? = null): Script { | ||
val script = ScriptImporter.preprocessScript(script) | ||
val name = if (pack != null) "$location(${pack.file.name})" else "$location" | ||
return ScriptCompiledClassCache.compile(script, name) | ||
} | ||
|
||
fun importScript(cx: Context, name: String, scope: Scriptable) { | ||
val script = getScript(name) | ||
script.exec(cx, scope) | ||
} | ||
|
||
override fun call(cx: Context, scope: Scriptable, thisObj: Scriptable, args: Array<Any>): Any? { | ||
if (args.size != 1) | ||
ScriptRuntime.typeError("invalid arguments: argument length must be 1") | ||
val name = ScriptRuntime.toString(args[0]) | ||
|
||
importScript(cx, name, scope) | ||
|
||
return Undefined.instance | ||
} | ||
|
||
override fun getFunctionName(): String = ScriptImporter.importScriptFunctionName | ||
|
||
fun init(scope: ScriptableObject) { | ||
usingContext { cx -> | ||
scope.defineProperty( | ||
ImportScriptRhinoFunctionImpl.functionName, | ||
ImportScriptRhinoFunctionImpl, | ||
ScriptableObject.READONLY or ScriptableObject.DONTENUM | ||
) | ||
} | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...Rtm/scripting/ScriptCompiledClassCache.kt → ...ripting/rhino/ScriptCompiledClassCache.kt
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
2 changes: 1 addition & 1 deletion
2
...va/com/anatawa12/fixRtm/scripting/Util.kt → .../anatawa12/fixRtm/scripting/rhino/Util.kt
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
File renamed without changes.