mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-27 17:33:21 +08:00
Temporary fix for scripts that call require
This commit is contained in:
parent
f8f4d89cd0
commit
3f76ac4cac
@ -13,6 +13,10 @@ import javax.script.ScriptEngine;
|
|||||||
import javax.script.ScriptEngineFactory;
|
import javax.script.ScriptEngineFactory;
|
||||||
import javax.script.ScriptEngineManager;
|
import javax.script.ScriptEngineManager;
|
||||||
|
|
||||||
|
import org.luaj.vm2.LuaValue;
|
||||||
|
import org.luaj.vm2.lib.OneArgFunction;
|
||||||
|
import org.luaj.vm2.script.LuajContext;
|
||||||
|
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.scripts.serializer.LuaSerializer;
|
import emu.grasscutter.scripts.serializer.LuaSerializer;
|
||||||
import emu.grasscutter.scripts.serializer.Serializer;
|
import emu.grasscutter.scripts.serializer.Serializer;
|
||||||
@ -31,11 +35,23 @@ public class ScriptLoader {
|
|||||||
throw new Exception("Script loader already initialized");
|
throw new Exception("Script loader already initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create script engine
|
||||||
sm = new ScriptEngineManager();
|
sm = new ScriptEngineManager();
|
||||||
engine = sm.getEngineByName("luaj");
|
engine = sm.getEngineByName("luaj");
|
||||||
factory = getEngine().getFactory();
|
factory = getEngine().getFactory();
|
||||||
|
|
||||||
|
// Lua stuff
|
||||||
fileType = "lua";
|
fileType = "lua";
|
||||||
serializer = new LuaSerializer();
|
serializer = new LuaSerializer();
|
||||||
|
|
||||||
|
// Set engine to replace require as a temporary fix to missing scripts
|
||||||
|
LuajContext ctx = (LuajContext) engine.getContext();
|
||||||
|
ctx.globals.set("require", new OneArgFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue arg0) {
|
||||||
|
return LuaValue.ZERO;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ScriptEngine getEngine() {
|
public static ScriptEngine getEngine() {
|
||||||
|
Loading…
Reference in New Issue
Block a user