Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
3f76ac4c
Commit
3f76ac4c
authored
Apr 29, 2022
by
Melledy
Browse files
Temporary fix for scripts that call require
parent
f8f4d89c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/scripts/ScriptLoader.java
View file @
3f76ac4c
...
...
@@ -13,6 +13,10 @@ import javax.script.ScriptEngine;
import
javax.script.ScriptEngineFactory
;
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.scripts.serializer.LuaSerializer
;
import
emu.grasscutter.scripts.serializer.Serializer
;
...
...
@@ -31,11 +35,23 @@ public class ScriptLoader {
throw
new
Exception
(
"Script loader already initialized"
);
}
// Create script engine
sm
=
new
ScriptEngineManager
();
engine
=
sm
.
getEngineByName
(
"luaj"
);
factory
=
getEngine
().
getFactory
();
// Lua stuff
fileType
=
"lua"
;
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
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment