Package org.luaj.vm2

Examples of org.luaj.vm2.LuaTable


  protected LuaTable new_Table(int n,int m) {
    return new LuaTable(n,m);
  }
 
  public void testInOrderIntegerKeyInsertion() {
    LuaTable t = new_Table();
   
    for ( int i = 1; i <= 32; ++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
    assertEquals( 0, t.getHashLength() );
   
    assertTrue( t.getArrayLength() >= 32 );
    assertTrue( t.getArrayLength() <= 64 );
   
  }
View Full Code Here


    assertTrue( t.getArrayLength() <= 64 );
   
  }
 
  public void testResize() {
    LuaTable t = new_Table();
   
    // NOTE: This order of insertion is important.
    t.set(3, LuaInteger.valueOf(3));
    t.set(1, LuaInteger.valueOf(1));
    t.set(5, LuaInteger.valueOf(5));
    t.set(4, LuaInteger.valueOf(4));
    t.set(6, LuaInteger.valueOf(6));
    t.set(2, LuaInteger.valueOf(2));
   
    for ( int i = 1; i < 6; ++i ) {
      assertEquals(LuaInteger.valueOf(i), t.get(i));
    }
   
    assertTrue( t.getArrayLength() >= 0 && t.getArrayLength() <= 2 );
    assertTrue( t.getHashLength() >= 4 );
  }
View Full Code Here

   
  public static void main(String[] args) throws Exception {
    System.out.println(script);
   
    // create an environment to run in
    LuaTable _G = JsePlatform.standardGlobals();
   
    // compile into a chunk, or load as a class
    InputStream is =  new ByteArrayInputStream( script.getBytes() );
    LuaValue chunk = LuaC.instance.load(is, "script",_G);
    chunk.call();
View Full Code Here

  public class ClientBindings {
    public final Bindings b;
    public final LuaTable env;
    public ClientBindings( Bindings b ) {
      this.b = b;
      this.env = new LuaTable();
      env.setmetatable(LuaTable.tableOf(new LuaValue[] { LuaValue.INDEX, _G }));
      this.copyBindingsToGlobals();
    }
View Full Code Here

  public DebugLib() {
  }
 
  private LuaTable init() {
    DEBUG_ENABLED = true;
    LuaTable t = new LuaTable();
    bind(t, DebugLib.class, NAMES, DEBUG);
    env.set("debug", t);
    PackageLib.instance.LOADED.set("debug", t);
    return t;
  }
View Full Code Here

    return env!=null? env: LuaValue.NIL;
  }

  static Varargs _setfenv(Varargs args) {
    LuaValue object = args.arg1();
    LuaTable table = args.checktable(2);
    object.setfenv(table);
    return object;
  }
View Full Code Here

    }
    if ( di == null )
      return NIL;

    // start a table
    LuaTable info = new LuaTable();
    LuaClosure c = di.closure;
    for (int i = 0, j = what.length(); i < j; i++) {
      switch (what.charAt(i)) {
        case 'S': {
          if ( c != null ) {
            Prototype p = c.p;
            info.set(WHAT, LUA);
            info.set(SOURCE, p.source);
            info.set(SHORT_SRC, valueOf(sourceshort(p)));
            info.set(LINEDEFINED, valueOf(p.linedefined));
            info.set(LASTLINEDEFINED, valueOf(p.lastlinedefined));
          } else {
            String shortName = di.func.tojstring();
            LuaString name = LuaString.valueOf("[Java] "+shortName);
            info.set(WHAT, JAVA);
            info.set(SOURCE, name);
            info.set(SHORT_SRC, valueOf(shortName));
            info.set(LINEDEFINED, LuaValue.MINUSONE);
            info.set(LASTLINEDEFINED, LuaValue.MINUSONE);
          }
          break;
        }
        case 'l': {
          int line = di.currentline();
          info.set( CURRENTLINE, valueOf(line) );
          break;
        }
        case 'u': {
          info.set(NUPS, valueOf(c!=null? c.p.nups: 0));
          break;
        }
        case 'n': {
          LuaString[] kind = di.getfunckind();
          info.set(NAME, kind!=null? kind[0]: QMARK);
          info.set(NAMEWHAT, kind!=null? kind[1]: EMPTYSTRING);
          break;
        }
        case 'f': {
          info.set( FUNC, di.func );
          break;
        }
        case 'L': {
          LuaTable lines = new LuaTable();
          info.set(ACTIVELINES, lines);
//          if ( di.luainfo != null ) {
//            int line = di.luainfo.currentline();
//            if ( line >= 0 )
//              lines.set(1, IntValue.valueOf(line));
View Full Code Here

      return varargsOf(FALSE, valueOf(e.toString()));
    }
  }

  static Varargs _getregistry(Varargs args) {
    return new LuaTable();
  }
View Full Code Here

        }
        return NIL;
      case 1: // "error", // ( message [,level] ) -> ERR
        throw new LuaError( arg1.isnil()? null: arg1.tojstring(), arg2.optint(1) );
      case 2: { // "setfenv", // (f, table) -> void
        LuaTable t = arg2.checktable();
        LuaValue f = getfenvobj(arg1);
        if ( ! f.isfunction() && ! f.isclosure() )
          error("'setfenv' cannot change environment of given object");
          f.setfenv(t);
          return f.isthread()? NONE: f;
View Full Code Here

        return args.subargs(i<0? n+i+2: i+1);
      }
      case 11: // "unpack", // (list [,i [,j]]) -> result1, ...
      {
        int na = args.narg();
        LuaTable t = args.checktable(1);
        int n = t.length();
        int i = na>=2? args.checkint(2): 1;
        int j = na>=3? args.checkint(3): n;
        n = j-i+1;
        if ( n<0 ) return NONE;
        if ( n==1 ) return t.get(i);
        if ( n==2 ) return varargsOf(t.get(i),t.get(j));
        LuaValue[] v = new LuaValue[n];
        for ( int k=0; k<n; k++ )
          v[k] = t.get(i+k);
        return varargsOf(v);
      }
      case 12: // "type",  // (v) -> value
        return valueOf(args.checkvalue(1).typename());
      case 13: // "rawequal", // (v1, v2) -> boolean
        return valueOf(args.checkvalue(1) == args.checkvalue(2));
      case 14: // "rawget", // (table, index) -> value
        return args.checktable(1).rawget(args.checkvalue(2));
      case 15: { // "rawset", // (table, index, value) -> table
        LuaTable t = args.checktable(1);
        t.rawset(args.checknotnil(2), args.checkvalue(3));
        return t;
      }
      case 16: { // "setmetatable", // (table, metatable) -> table
        final LuaValue t = args.arg1();
        final LuaValue mt0 = t.getmetatable();
        if ( mt0!=null && !mt0.rawget(METATABLE).isnil() )
          error("cannot change a protected metatable");
        final LuaValue mt = args.checkvalue(2);
        return t.setmetatable(mt.isnil()? null: mt.checktable());
      }
      case 17: { // "tostring", // (e) -> value
        LuaValue arg = args.checkvalue(1);
        LuaValue h = arg.metatag(TOSTRING);
        if ( ! h.isnil() )
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.