Package org.luaj.vm2

Examples of org.luaj.vm2.LuaTable


    @Override
    public Varargs invoke(Varargs args) {
      LuaMap map = new LuaMap(instance, new HashMap<LuaValue,LuaValue>());
     
      if (args.istable(2)) {
        LuaTable table = args.checktable(2);
        LuaValue k = LuaValue.NIL;
       
        while (true) {
           Varargs n = table.next(k);
          
           if ((k = n.arg1()).isnil())
             break;

           LuaValue v = n.arg(2);
View Full Code Here


    assertTrue( t.getArrayLength() >= 0 && t.getArrayLength() <= 2 );
    assertTrue( t.getHashLength() >= 4 );
  }
 
  public void testOutOfOrderIntegerKeyInsertion() {
    LuaTable t = new_Table();
   
    for ( int i = 32; i > 0; --i ) {
      t.set( i, LuaString.valueOf( "Test Value! "+i ) );
    }

    // Ensure all keys are still there.
    for ( int i = 1; i <= 32; ++i ) {
      assertEquals( "Test Value! "+i, t.get( i ).tojstring() );
    }
   
    // Ensure capacities make sense
    assertTrue( t.getArrayLength() >= 0 );
    assertTrue( t.getArrayLength() <= 6 );
   
    assertTrue( t.getHashLength() >= 16 );
    assertTrue( t.getHashLength() <= 64 );
   
  }
View Full Code Here

    assertTrue( t.getHashLength() <= 64 );
   
  }
 
  public void testStringAndIntegerKeys() {
    LuaTable t = new_Table();
   
    for ( int i = 0; i < 10; ++i ) {
      LuaString str = LuaString.valueOf( String.valueOf( i ) );
      t.set( i, str );
      t.set( str, LuaInteger.valueOf( i ) );
    }
   
    assertTrue( t.getArrayLength() >= 9 ); // 1, 2, ..., 9
    assertTrue( t.getArrayLength() <= 18 );
    assertTrue( t.getHashLength() >= 11 ); // 0, "0", "1", ..., "9"
    assertTrue( t.getHashLength() <= 33 );
   
    LuaValue[] keys = t.keys();
   
    int intKeys = 0;
    int stringKeys = 0;
   
    assertEquals( 20, keys.length );
View Full Code Here

    assertEquals( 0x03FF, intKeys );
    assertEquals( 0x03FF, stringKeys );
  }
 
  public void testBadInitialCapacity() {
    LuaTable t = new_Table(0, 1);
   
    t.set( "test", LuaString.valueOf("foo") );
    t.set( "explode", LuaString.valueOf("explode") );
    assertEquals( 2, t.keyCount() );
  }
View Full Code Here

    t.set( "explode", LuaString.valueOf("explode") );
    assertEquals( 2, t.keyCount() );
  }
 
  public void testRemove0() {
    LuaTable t = new_Table(2, 0);
   
    t.set( 1, LuaString.valueOf("foo") );
    t.set( 2, LuaString.valueOf("bah") );
    assertNotSame(LuaValue.NIL, t.get(1));
    assertNotSame(LuaValue.NIL, t.get(2));
    assertEquals(LuaValue.NIL, t.get(3));
   
    t.set( 1, LuaValue.NIL );
    t.set( 2, LuaValue.NIL );
    t.set( 3, LuaValue.NIL );
    assertEquals(LuaValue.NIL, t.get(1));
    assertEquals(LuaValue.NIL, t.get(2));
    assertEquals(LuaValue.NIL, t.get(3));
  }
View Full Code Here

    assertEquals(LuaValue.NIL, t.get(2));
    assertEquals(LuaValue.NIL, t.get(3));
  }
 
  public void testRemove1() {
    LuaTable t = new_Table(0, 1);
    assertEquals( 0, t.keyCount() );
   
    t.set( "test", LuaString.valueOf("foo") );
    assertEquals( 1, t.keyCount() );
    t.set( "explode", LuaValue.NIL );
    assertEquals( 1, t.keyCount() );
    t.set( 42, LuaValue.NIL );
    assertEquals( 1, t.keyCount() );
    t.set( new_Table(), LuaValue.NIL );
    assertEquals( 1, t.keyCount() );
    t.set( "test", LuaValue.NIL );
    assertEquals( 0, t.keyCount() );
   
    t.set( 10, LuaInteger.valueOf( 5 ) );
    t.set( 10, LuaValue.NIL );
    assertEquals( 0, t.keyCount() );
  }
View Full Code Here

    t.set( 10, LuaValue.NIL );
    assertEquals( 0, t.keyCount() );
  }
 
  public void testRemove2() {
    LuaTable t = new_Table(0, 1);
   
    t.set( "test", LuaString.valueOf("foo") );
    t.set( "string", LuaInteger.valueOf( 10 ) );
    assertEquals( 2, t.keyCount() );
   
    t.set( "string", LuaValue.NIL );
    t.set( "three", LuaDouble.valueOf( 3.14 ) );
    assertEquals( 2, t.keyCount() );
   
    t.set( "test", LuaValue.NIL );
    assertEquals( 1, t.keyCount() );
   
    t.set( 10, LuaInteger.valueOf( 5 ) );
    assertEquals( 2, t.keyCount() );
   
    t.set( 10, LuaValue.NIL );
    assertEquals( 1, t.keyCount() );
   
    t.set( "three", LuaValue.NIL );
    assertEquals( 0, t.keyCount() );
  }
View Full Code Here

      // expected
    }
  }

  public void testLuaTableToJavaIntArray() {
    LuaTable t = new LuaTable();
    t.set(1, LuaInteger.valueOf(222) );
    t.set(2, LuaInteger.valueOf(333) );
    int[] i = null;
    Object o = CoerceLuaToJava.coerce(t, int[].class);
    assertEquals( int[].class, o.getClass() );
    i = (int[]) o;
    assertEquals( 2, i.length );
View Full Code Here

    t.set( "three", LuaValue.NIL );
    assertEquals( 0, t.keyCount() );
  }

  public void testInOrderlen() {
    LuaTable t = new_Table();
   
    for ( int i = 1; i <= 32; ++i ) {
      LuaValue v = LuaString.valueOf( "Test Value! "+i );
      t.set( i, v );
      assertEquals( i, t.length() );
      assertEquals( i, t.maxn() );
    }
  }
View Full Code Here

  }
 
  public void testIntArrayScoringTables() {
    int a = 5;
    LuaValue la = LuaInteger.valueOf(a);
    LuaTable tb = new LuaTable();
    tb.set( 1, la );
    LuaTable tc = new LuaTable();
    tc.set( 1, tb );
   
    int saa = CoerceLuaToJava.getCoercion(int.class).score(la);
    int sab = CoerceLuaToJava.getCoercion(int[].class).score(la);
    int sac = CoerceLuaToJava.getCoercion(int[][].class).score(la);
    assertTrue( saa < sab );
View Full Code Here

TOP

Related Classes of org.luaj.vm2.LuaTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.