[3.0-beta2] throw java.lang.ArrayIndexOutOfBoundsException
Brought to you by:
ian_farmer,
jim_roseborough
code:
ScriptEngine engine = scriptEngineManager.getEngineByName("luaj");
engine.eval("--呵呵\nlocal x,y = 38,47\nlocal bossMetaId = 5390209");
out:
Exception in thread "main" javax.script.ScriptException: eval threw javax.script.ScriptException: load script: java.lang.ArrayIndexOutOfBoundsException: 32
at org.luaj.vm2.script.LuaScriptEngine.compile(LuaScriptEngine.java:94)
at org.luaj.vm2.script.LuaScriptEngine.eval(LuaScriptEngine.java:112)
at org.luaj.vm2.script.LuaScriptEngine.eval(LuaScriptEngine.java:106)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
at net.szh.TScript.main(TScript.java:16)
I found that , luaj can't handle Chinese char.
when I put strings with Chinese into script , it throws that:
Exception in thread "main" org.luaj.vm2.LuaError: load test1.lua: java.lang.ArrayIndexOutOfBoundsException: 32
at org.luaj.vm2.LuaValue.error(Unknown Source)
at org.luaj.vm2.Globals.load(Unknown Source)
at org.luaj.vm2.Globals.load(Unknown Source)
at net.duzc2.test.luaj.lualib.LuaLibLoad.main(LuaLibLoad.java:54)
and even,
if I run the only command in script :
print("你好")
it will print wrong:
`}
I guess there must be some bugs in org.luaj.vm2.Globals.UTF8Stream class .
org.luaj.vm2.LuaString.encodeToUtf8(char[], int, byte[], int)
I guess something wrong in this method...
I got it!
when I write
LuaValue chunk1 = globals.load(
new InputStreamReader(LuaLibLoad.class
.getResourceAsStream("test1.lua")), "test1.lua");
it throws that exception
and I write it as :
LuaValue chunk1 = globals.load(LuaLibLoad.class
.getResourceAsStream("test1.lua"), "test1.lua","t",globals);
works!
I think there is must be a bug in org.luaj.vm2.Globals.UTF8Stream.
I have a different way to encode utf8:
maybe it's slow , but right ,I use it in my system in China.
Thank you for your reply
I believe this was a problem in the beta release but has been fixed for version 3.0.