Updated to Lua 5.5
This commit is contained in:
@@ -128,7 +128,7 @@ public class LuaJC implements Globals.Loader {
|
||||
}
|
||||
|
||||
private boolean requiresInterpreterDelegate(Prototype p) {
|
||||
return hasToCloseLocals(p) || usesInterpreterOnlyRuntimeSemantics(p);
|
||||
return hasToCloseLocals(p) || hasNamedVarargTables(p) || usesInterpreterOnlyRuntimeSemantics(p);
|
||||
}
|
||||
|
||||
private boolean hasToCloseLocals(Prototype p) {
|
||||
@@ -148,6 +148,20 @@ public class LuaJC implements Globals.Loader {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasNamedVarargTables(Prototype p) {
|
||||
if (p.varargname != null) {
|
||||
return true;
|
||||
}
|
||||
if (p.p != null) {
|
||||
for (int i = 0; i < p.p.length; i++) {
|
||||
if (p.p[i] != null && hasNamedVarargTables(p.p[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean usesInterpreterOnlyRuntimeSemantics(Prototype p) {
|
||||
if (prototypeReferences(p, "xpcall") || prototypeReferences(p, "debug")) {
|
||||
return true;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin
|
||||
private static final String __NAME__ = "Luaj";
|
||||
private static final String __SHORT_NAME__ = "Luaj";
|
||||
private static final String __LANGUAGE__ = "lua";
|
||||
private static final String __LANGUAGE_VERSION__ = "5.4";
|
||||
private static final String __LANGUAGE_VERSION__ = "5.5";
|
||||
private static final String __ARGV__ = "arg";
|
||||
private static final String __FILENAME__ = "?";
|
||||
|
||||
|
||||
@@ -499,7 +499,8 @@ public class FragmentsTest extends TestSuite {
|
||||
LuaValue.valueOf(2),
|
||||
LuaValue.valueOf(228),
|
||||
LuaValue.valueOf(97),
|
||||
LuaValue.valueOf(2)
|
||||
LuaValue.valueOf(2),
|
||||
LuaValue.valueOf(3)
|
||||
}),
|
||||
"local s = utf8.char(97, 228)\nlocal iter, state, var = utf8.codes(s)\nlocal _, cp = iter(state, var)\nreturn utf8.len(s), utf8.codepoint(s, 2), cp, utf8.offset(s, 2)\n");
|
||||
}
|
||||
@@ -550,7 +551,7 @@ public class FragmentsTest extends TestSuite {
|
||||
runFragment(
|
||||
LuaValue.varargsOf(new LuaValue[] {
|
||||
LuaValue.valueOf(123),
|
||||
LuaValue.valueOf(84)
|
||||
LuaValue.valueOf(85)
|
||||
}),
|
||||
"local dumped = string.dump(function() return 123 end)\n" +
|
||||
"local loaded = assert(load(dumped, 'dumped', 'b'))\n" +
|
||||
@@ -565,11 +566,21 @@ public class FragmentsTest extends TestSuite {
|
||||
LuaValue.FALSE,
|
||||
LuaValue.valueOf(Long.MAX_VALUE),
|
||||
LuaValue.valueOf(Long.MIN_VALUE),
|
||||
LuaValue.valueOf("Lua 5.4")
|
||||
LuaValue.valueOf("Lua 5.5")
|
||||
}),
|
||||
"return math.type(3), math.tointeger(3.0), math.ult(-1, 1), math.maxinteger, math.mininteger, _VERSION\n");
|
||||
}
|
||||
|
||||
public void testTableCreate55() {
|
||||
runFragment(
|
||||
LuaValue.varargsOf(new LuaValue[] {
|
||||
LuaValue.valueOf(3),
|
||||
LuaValue.valueOf("x"),
|
||||
LuaValue.valueOf("x")
|
||||
}),
|
||||
"local t = table.create(3, 'x')\nreturn #t, t[1], t[3]\n");
|
||||
}
|
||||
|
||||
public void testHexFloatLiteralAndTonumber() {
|
||||
runFragment(
|
||||
LuaValue.varargsOf(new LuaValue[] {
|
||||
@@ -734,6 +745,101 @@ public class FragmentsTest extends TestSuite {
|
||||
}
|
||||
}
|
||||
|
||||
public void testGlobalDeclaration55() {
|
||||
runFragment(
|
||||
LuaValue.varargsOf(new LuaValue[] {
|
||||
LuaValue.valueOf(7),
|
||||
LuaValue.valueOf(7)
|
||||
}),
|
||||
"global answer = 7\nlocal function f() return answer end\nreturn f(), answer\n");
|
||||
}
|
||||
|
||||
public void testGlobalDeclarationRejectsUndeclaredName() {
|
||||
Globals globals = JsePlatform.debugGlobals();
|
||||
try {
|
||||
switch (TEST_TYPE) {
|
||||
case TEST_TYPE_LUAJC:
|
||||
LuaJC.install(globals);
|
||||
globals.load(new StringReader("global answer = 7\nreturn missing\n"), getName());
|
||||
break;
|
||||
default:
|
||||
globals.compilePrototype(new StringReader("global answer = 7\nreturn missing\n"), getName());
|
||||
break;
|
||||
}
|
||||
fail("expected LuaError");
|
||||
} catch (LuaError e) {
|
||||
assertTrue(e.getMessage().indexOf("is not declared") >= 0);
|
||||
} catch (Exception e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void testGlobalConstRejectsAssignment55() {
|
||||
Globals globals = JsePlatform.debugGlobals();
|
||||
try {
|
||||
switch (TEST_TYPE) {
|
||||
case TEST_TYPE_LUAJC:
|
||||
LuaJC.install(globals);
|
||||
globals.load(new StringReader("global <const> answer = 7\nanswer = 8\n"), getName());
|
||||
break;
|
||||
default:
|
||||
globals.compilePrototype(new StringReader("global <const> answer = 7\nanswer = 8\n"), getName());
|
||||
break;
|
||||
}
|
||||
fail("expected LuaError");
|
||||
} catch (LuaError e) {
|
||||
assertTrue(e.getMessage().indexOf("attempt to assign to const variable") >= 0);
|
||||
} catch (Exception e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void testNamedVarargTable55() {
|
||||
runFragment(
|
||||
LuaValue.varargsOf(new LuaValue[] {
|
||||
LuaValue.valueOf(1),
|
||||
LuaValue.valueOf(2),
|
||||
LuaValue.valueOf(2),
|
||||
LuaValue.valueOf(3),
|
||||
LuaValue.valueOf(2)
|
||||
}),
|
||||
"local function f(a, ...rest)\n" +
|
||||
" return a, rest[1], rest.n, rest[2], select('#', ...)\n" +
|
||||
"end\n" +
|
||||
"return f(1, 2, 3)\n");
|
||||
}
|
||||
|
||||
public void testNamedVarargDumpRoundTrip55() {
|
||||
runFragment(
|
||||
LuaValue.varargsOf(new LuaValue[] {
|
||||
LuaValue.valueOf(2),
|
||||
LuaValue.valueOf(5)
|
||||
}),
|
||||
"local dumped = string.dump(function(...rest) return rest.n, rest[2] end)\n" +
|
||||
"local loaded = assert(load(dumped, 'dumped', 'b'))\n" +
|
||||
"return loaded(4, 5)\n");
|
||||
}
|
||||
|
||||
public void testForLoopVariableRejectsAssignment55() {
|
||||
Globals globals = JsePlatform.debugGlobals();
|
||||
try {
|
||||
switch (TEST_TYPE) {
|
||||
case TEST_TYPE_LUAJC:
|
||||
LuaJC.install(globals);
|
||||
globals.load(new StringReader("for i = 1, 3 do i = 7 end\n"), getName());
|
||||
break;
|
||||
default:
|
||||
globals.compilePrototype(new StringReader("for i = 1, 3 do i = 7 end\n"), getName());
|
||||
break;
|
||||
}
|
||||
fail("expected LuaError");
|
||||
} catch (LuaError e) {
|
||||
assertTrue(e.getMessage().indexOf("attempt to assign to const variable") >= 0);
|
||||
} catch (Exception e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void testCoroutineClose54() {
|
||||
runFragment(
|
||||
LuaValue.varargsOf(new LuaValue[] {
|
||||
@@ -1024,9 +1130,9 @@ public class FragmentsTest extends TestSuite {
|
||||
public void testNumericForUpvalues() {
|
||||
runFragment( LuaValue.valueOf(8),
|
||||
"for i = 3,4 do\n"+
|
||||
" i = i + 5\n"+
|
||||
" local j = i + 5\n"+
|
||||
" local a = function()\n"+
|
||||
" return i\n"+
|
||||
" return j\n"+
|
||||
" end\n" +
|
||||
" return a()\n"+
|
||||
"end\n");
|
||||
|
||||
@@ -83,9 +83,9 @@ public class ScriptEngineTests extends TestSuite {
|
||||
ScriptEngine e = new ScriptEngineManager().getEngineByName("luaj");
|
||||
ScriptEngineFactory f = e.getFactory();
|
||||
assertEquals("Luaj", f.getEngineName());
|
||||
assertEquals("Lua 5.4", f.getEngineVersion());
|
||||
assertEquals("Lua 5.5", f.getEngineVersion());
|
||||
assertEquals("lua", f.getLanguageName());
|
||||
assertEquals("5.4", f.getLanguageVersion());
|
||||
assertEquals("5.5", f.getLanguageVersion());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user