Correctly remove values stored in the array-part of a table.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<project default="all">
|
||||
<property name="version" value="0.12"/>
|
||||
<property name="version" value="0.13"/>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="build"/>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
12
src/test/res/test8.lua
Normal 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])
|
||||
Reference in New Issue
Block a user