Correctly remove values stored in the array-part of a table.

This commit is contained in:
Ian Farmer
2007-12-12 19:19:03 +00:00
parent eef737fde1
commit 60cc93d64c
5 changed files with 35 additions and 1 deletions

View File

@@ -362,6 +362,7 @@ public class LTable extends LValue {
final int index = key - 1;
if ( index < m_vector.length ) {
if ( m_vector[ index ] != LNil.NIL ) {
m_vector[ index ] = LNil.NIL;
--m_arrayEntries;
}
return;

View File

@@ -102,6 +102,23 @@ public class LTableTest extends TestCase {
assertEquals( 2, t.size() );
}
public void testRemove0() {
LTable t = new LTable(2, 0);
t.put( 1, new LString("foo") );
t.put( 2, new LString("bah") );
assertNotSame(LNil.NIL, t.get(1));
assertNotSame(LNil.NIL, t.get(2));
assertEquals(LNil.NIL, t.get(3));
t.put( 1, LNil.NIL );
t.put( 2, LNil.NIL );
t.put( 3, LNil.NIL );
assertEquals(LNil.NIL, t.get(1));
assertEquals(LNil.NIL, t.get(2));
assertEquals(LNil.NIL, t.get(3));
}
public void testRemove1() {
LTable t = new LTable(0, 1);

View File

@@ -42,6 +42,10 @@ public class LuaJTest extends TestCase {
runTest( "test7" );
}
public void testTest8() throws IOException, InterruptedException {
runTest( "test8" );
}
public void testAutoload() throws IOException, InterruptedException {
runTest( "autoload" );
}

12
src/test/res/test8.lua Normal file
View File

@@ -0,0 +1,12 @@
t = {}
t[1] = "foo"
t[2] = "bah"
print(t[1])
print(t[2])
print(t[3])
t[1] = nil
t[2] = nil
print(t[1])
print(t[2])
print(t[3])