Fix a bug in how OP_SETLIST is handled. Includes new test case.
This commit is contained in:
@@ -367,15 +367,16 @@ public class CallFrame {
|
|||||||
case StackState.OP_SETLIST: {
|
case StackState.OP_SETLIST: {
|
||||||
b = StackState.GETARG_B(i);
|
b = StackState.GETARG_B(i);
|
||||||
c = StackState.GETARG_C(i);
|
c = StackState.GETARG_C(i);
|
||||||
|
int listBase = base + a;
|
||||||
if (b == 0) {
|
if (b == 0) {
|
||||||
b = top - 1;
|
b = top - listBase - 1;
|
||||||
}
|
}
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
c = code[pc++];
|
c = code[pc++];
|
||||||
}
|
}
|
||||||
table = this.stack[base + a];
|
table = this.stack[base + a];
|
||||||
for (int index = 1; index <= b; index++) {
|
for (int index = 1; index <= b; index++) {
|
||||||
val = this.stack[base + a + index];
|
val = this.stack[listBase + index];
|
||||||
table.luaSetTable(this, this.state.avail, table,
|
table.luaSetTable(this, this.state.avail, table,
|
||||||
new LInteger(index), val);
|
new LInteger(index), val);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ public class LuaJTest extends TestCase {
|
|||||||
runTest( "upvalues2" );
|
runTest( "upvalues2" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSetlist() throws IOException, InterruptedException {
|
||||||
|
runTest( "setlist" );
|
||||||
|
}
|
||||||
|
|
||||||
private void runTest( String testName ) throws IOException, InterruptedException {
|
private void runTest( String testName ) throws IOException, InterruptedException {
|
||||||
// add LuaJava bindings
|
// add LuaJava bindings
|
||||||
LuaJava.install();
|
LuaJava.install();
|
||||||
|
|||||||
27
src/test/res/setlist.lua
Normal file
27
src/test/res/setlist.lua
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
-- This file attemps to test that the setlist instruction works
|
||||||
|
|
||||||
|
local list = { 1, 2, 3 }
|
||||||
|
|
||||||
|
-- for now, can't just do:
|
||||||
|
-- for x, y in pairs( list ) do
|
||||||
|
-- since our tables don't iterate over keys in the same order
|
||||||
|
-- as regular Lua.
|
||||||
|
|
||||||
|
print( #list )
|
||||||
|
for i = 1, 3 do
|
||||||
|
print("list[", i, "]=", list[i])
|
||||||
|
end
|
||||||
|
|
||||||
|
local function printList( l )
|
||||||
|
for i = 1, #l do
|
||||||
|
print(i, "->", l[i] )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
printList( { "a", "b", "c" } )
|
||||||
|
|
||||||
|
local function foo()
|
||||||
|
return "d", "e", "f", "g"
|
||||||
|
end
|
||||||
|
|
||||||
|
printList( { foo() } )
|
||||||
BIN
src/test/res/setlist.luac
Normal file
BIN
src/test/res/setlist.luac
Normal file
Binary file not shown.
Reference in New Issue
Block a user