Package org.luaj.vm2

Examples of org.luaj.vm2.LuaTable


  public TableLib() {
  }

  private LuaTable init() {
    LuaTable t = new LuaTable();
    bind(t, TableLib.class, new String[] { "getn", "maxn", }, 1 );
    bind(t, TableLibV.class, new String[] {
      "remove", "concat", "insert", "sort", "foreach", "foreachi", } );
    env.set("table", t);
    PackageLib.instance.LOADED.set("table", t);
View Full Code Here


  static final class TableLibV extends VarArgFunction {
    public Varargs invoke(Varargs args) {
      switch ( opcode ) {
      case 0: { // "remove" (table [, pos]) -> removed-ele
        LuaTable table = args.checktable(1);
        int pos = args.narg()>1? args.checkint(2): 0;
        return table.remove(pos);
      }
      case 1: { // "concat" (table [, sep [, i [, j]]]) -> string
        LuaTable table = args.checktable(1);
        return table.concat(
            args.optstring(2,LuaValue.EMPTYSTRING),
            args.optint(3,1),
            args.isvalue(4)? args.checkint(4): table.length() );
      }
      case 2: { // "insert" (table, [pos,] value) -> prev-ele
        final LuaTable table = args.checktable(1);
        final int pos = args.narg()>2? args.checkint(2): 0;
        final LuaValue value = args.arg( args.narg()>2? 3: 2 );
        table.insert( pos, value );
        return NONE;
      }
      case 3: { // "sort" (table [, comp]) -> void
        LuaTable table = args.checktable(1);
        LuaValue compare = (args.isnoneornil(2)? NIL: args.checkfunction(2));
        table.sort( compare );
        return NONE;
      }
      case 4: { // (table, func) -> void
        return args.checktable(1).foreach( args.checkfunction(2) );
      }
View Full Code Here

      if ( e < 0 )
        e = fname.m_length;
      LuaString key = fname.substring(b, e);
      LuaValue val = table.rawget(key);
      if ( val.isnil() ) { /* no such field? */
        LuaTable field = new LuaTable(); /* new table for field */
        table.set(key, field);
        table = field;
      } else if ( ! val.istable() ) {  /* field has a non-table value? */
        return null;
      } else {
View Full Code Here

        error("loop or previous error loading module '"+name+"'");
      return loaded;
    }

    /* else must load it; iterate over available loaders */
    LuaTable tbl = PACKAGE.get(_LOADERS).checktable();
    StringBuffer sb = new StringBuffer();
    LuaValue chunk = null;
    for ( int i=1; true; i++ ) {
      LuaValue loader = tbl.get(i);
      if ( loader.isnil() ) {
        error( "module '"+name+"' not found: "+name+sb );       
        }
           
        /* call loader with module name as argument */
 
View Full Code Here

  public Varargs invoke(Varargs args) {
    try {
      switch ( opcode ) {
      case INIT: {
        LuaTable t = new LuaTable();
        bind( t, LuajavaLib.class, NAMES, BINDCLASS );
        env.set("luajava", t);
        PackageLib.instance.LOADED.set("luajava", t);
        return t;
      }
View Full Code Here

    public LuaValue call(LuaValue arg) {
      switch ( opcode ) {
      case OP_REQUIRE:
        return lib.require(arg);
      case OP_SEEALL: {
        LuaTable t = arg.checktable();
        LuaValue m = t.getmetatable();
        if ( m == null )
          t.setmetatable(m=tableOf());
        m.set( INDEX, LuaThread.getGlobals() );
        return NONE;
      }
      }
      return NIL;
View Full Code Here

          } finally {
            try { is.close(); } catch ( IOException ioe ) {}
          }
        }
      };
      LuaTable loaders = _G.get("package").get("loaders").checktable();
      loaders.insert(1, loader);
      org.luaj.vm2.lib.BaseLib.instance.STDOUT = printStream;
      loader.call(LuaValue.valueOf(test)).invoke(LuaValue.valueOf(test));
    } finally {
      printStream.close();
    }
View Full Code Here

    this.instance = instance;
    instance.load(new MetaLib(instance));
  }

  public LuaValue call(LuaValue env) {
    LuaTable meta = new LuaTable(0,2);
    meta.set("__call", new create(instance));
   
    LuaTable table = new LuaTable(0,50);
    table.setmetatable(meta);
   
    new one_arg(table, 0, "size");
    new one_arg(table, 1, "get_type");

    new two_arg(table, 0, "set_size");
View Full Code Here

    public MetaLib(LuaInstance instance) {
      this.instance = instance;
    }

    public LuaValue call(LuaValue env) {
      LuaTable meta = new LuaTable(0, 5);
      new one_arg(meta, 0, "__len")// size
      new one_arg(meta, 2, "__tostring");
      new get_int(meta, 6, "__index");
      new set_int(meta, 8, "__newindex");
     
View Full Code Here

 
  public StringLib() {
  }

  public LuaValue call(LuaValue arg) {
    LuaTable t = new LuaTable();
    bind(t, StringLib1.class, new String[] {
      "dump", "len", "lower", "reverse", "upper", } );
    bind(t, StringLibV.class, new String[] {
      "byte", "char", "find", "format",
      "gmatch", "gsub", "match", "rep",
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.