Lua 5.2 compatibility fixes.
This commit is contained in:
@@ -426,22 +426,15 @@ public class LuaClosure extends LuaFunction {
|
|||||||
|
|
||||||
case Lua.OP_TFORCALL: /* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */
|
case Lua.OP_TFORCALL: /* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */
|
||||||
v = stack[a].invoke(varargsOf(stack[a+1],stack[a+2]));
|
v = stack[a].invoke(varargsOf(stack[a+1],stack[a+2]));
|
||||||
|
c = (i>>14) & 0x1ff;
|
||||||
|
while (--c >= 0)
|
||||||
|
stack[a+3+c] = v.arg(c+1);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case Lua.OP_TFORLOOP: /*
|
case Lua.OP_TFORLOOP: /* A sBx if R(A) != nil then ps+= sBx */
|
||||||
* A C R(A+3), ... ,R(A+2+C):= R(A)(R(A+1),
|
if (!stack[a+1].isnil()) { /* continue loop? */
|
||||||
* R(A+2)): if R(A+3) ~= nil then R(A+2)=R(A+3)
|
stack[a] = stack[a+1]; /* save control varible. */
|
||||||
* else pc++
|
pc += (i>>>14)-0x1ffff;
|
||||||
*/
|
|
||||||
// TODO: stack call on for loop body, such as: stack[a].call(ci);
|
|
||||||
v = stack[a].invoke(varargsOf(stack[a+1],stack[a+2]));
|
|
||||||
if ( (o=v.arg1()).isnil() )
|
|
||||||
++pc;
|
|
||||||
else {
|
|
||||||
stack[a+2] = stack[a+3] = o;
|
|
||||||
for ( c=(i>>14)&0x1ff; c>1; --c )
|
|
||||||
stack[a+2+c] = v.arg(c);
|
|
||||||
v = NONE; // todo: necessary?
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -514,15 +507,13 @@ public class LuaClosure extends LuaFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private UpValue findupval(LuaValue[] stack, short idx, UpValue[] openups) {
|
private UpValue findupval(LuaValue[] stack, short idx, UpValue[] openups) {
|
||||||
if (idx <= 0)
|
|
||||||
error("Upvalue index must be > 0");
|
|
||||||
final int n = openups.length;
|
final int n = openups.length;
|
||||||
for (int i = 0; i < n; ++i)
|
for (int i = 0; i < n; ++i)
|
||||||
if (openups[i] != null && openups[i].index == idx)
|
if (openups[i] != null && openups[i].index == idx)
|
||||||
return openups[i];
|
return openups[i];
|
||||||
for (int i = 0; i < n; ++i)
|
for (int i = 0; i < n; ++i)
|
||||||
if (openups[i] == null)
|
if (openups[i] == null)
|
||||||
return openups[idx] = new UpValue(stack, idx);
|
return openups[i] = new UpValue(stack, idx);
|
||||||
this.error("No space for upvalue");
|
this.error("No space for upvalue");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class FragmentsTest extends TestSuite {
|
|||||||
public void runFragment( Varargs expected, String script ) {
|
public void runFragment( Varargs expected, String script ) {
|
||||||
try {
|
try {
|
||||||
String name = getName();
|
String name = getName();
|
||||||
LuaTable _G = org.luaj.vm2.lib.jse.JsePlatform.standardGlobals();
|
LuaTable _G = org.luaj.vm2.lib.jse.JsePlatform.debugGlobals();
|
||||||
InputStream is = new ByteArrayInputStream(script.getBytes("UTF-8"));
|
InputStream is = new ByteArrayInputStream(script.getBytes("UTF-8"));
|
||||||
LuaValue chunk ;
|
LuaValue chunk ;
|
||||||
switch ( TEST_TYPE ) {
|
switch ( TEST_TYPE ) {
|
||||||
@@ -83,6 +83,7 @@ public class FragmentsTest extends TestSuite {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
chunk = LuaC.instance.load( is, name, _G );
|
chunk = LuaC.instance.load( is, name, _G );
|
||||||
|
Print.print(((LuaClosure)chunk).p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Varargs actual = chunk.invoke();
|
Varargs actual = chunk.invoke();
|
||||||
@@ -109,35 +110,10 @@ public class FragmentsTest extends TestSuite {
|
|||||||
"end\n");
|
"end\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testVarVarargsUseArg() {
|
|
||||||
runFragment( LuaValue.varargsOf( new LuaValue[] {
|
|
||||||
LuaValue.valueOf("a"),
|
|
||||||
LuaValue.valueOf(2),
|
|
||||||
LuaValue.valueOf("b"),
|
|
||||||
LuaValue.valueOf("c"),
|
|
||||||
LuaValue.NIL }),
|
|
||||||
"function q(a,...)\n" +
|
|
||||||
" return a,arg.n,arg[1],arg[2],arg[3]\n" +
|
|
||||||
"end\n" +
|
|
||||||
"return q('a','b','c')\n" );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testVarVarargsUseBoth() {
|
|
||||||
runFragment( LuaValue.varargsOf( new LuaValue[] {
|
|
||||||
LuaValue.valueOf("a"),
|
|
||||||
LuaValue.valueOf("nil"),
|
|
||||||
LuaValue.valueOf("b"),
|
|
||||||
LuaValue.valueOf("c")}),
|
|
||||||
"function r(a,...)\n" +
|
|
||||||
" return a,type(arg),...\n" +
|
|
||||||
"end\n" +
|
|
||||||
"return r('a','b','c')\n" );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testArgVarargsUseBoth() {
|
public void testArgVarargsUseBoth() {
|
||||||
runFragment( LuaValue.varargsOf( new LuaValue[] {
|
runFragment( LuaValue.varargsOf( new LuaValue[] {
|
||||||
LuaValue.NIL,
|
LuaValue.valueOf("a"),
|
||||||
LuaValue.valueOf("b"),
|
LuaValue.valueOf("b"),
|
||||||
LuaValue.valueOf("c")}),
|
LuaValue.valueOf("c")}),
|
||||||
"function v(arg,...)\n" +
|
"function v(arg,...)\n" +
|
||||||
@@ -148,7 +124,7 @@ public class FragmentsTest extends TestSuite {
|
|||||||
|
|
||||||
public void testArgParamUseNone() {
|
public void testArgParamUseNone() {
|
||||||
// the name "arg" is treated specially, and ends up masking the argument value in 5.1
|
// the name "arg" is treated specially, and ends up masking the argument value in 5.1
|
||||||
runFragment( LuaValue.valueOf("table"),
|
runFragment( LuaValue.valueOf("string"),
|
||||||
"function v(arg,...)\n" +
|
"function v(arg,...)\n" +
|
||||||
" return type(arg)\n" +
|
" return type(arg)\n" +
|
||||||
"end\n" +
|
"end\n" +
|
||||||
@@ -197,22 +173,7 @@ public class FragmentsTest extends TestSuite {
|
|||||||
"print( 'c=', c )\n" +
|
"print( 'c=', c )\n" +
|
||||||
"return c\n" );
|
"return c\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNeedsArgAndHasArg() {
|
|
||||||
runFragment( LuaValue.varargsOf(LuaValue.valueOf(333),LuaValue.NIL,LuaValue.valueOf(222)),
|
|
||||||
"function r(q,...)\n"+
|
|
||||||
" local a=arg\n"+
|
|
||||||
" return a and a[2]\n"+
|
|
||||||
"end\n" +
|
|
||||||
"function s(q,...)\n"+
|
|
||||||
" local a=arg\n"+
|
|
||||||
" local b=...\n"+
|
|
||||||
" return a and a[2],b\n"+
|
|
||||||
"end\n" +
|
|
||||||
"return r(111,222,333),s(111,222,333)" );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNonAsciiStringLiterals() {
|
public void testNonAsciiStringLiterals() {
|
||||||
runFragment( LuaValue.valueOf("7,8,12,10,9,11,133,222"),
|
runFragment( LuaValue.valueOf("7,8,12,10,9,11,133,222"),
|
||||||
"local a='\\a\\b\\f\\n\\t\\v\\133\\222'\n"+
|
"local a='\\a\\b\\f\\n\\t\\v\\133\\222'\n"+
|
||||||
|
|||||||
Reference in New Issue
Block a user