Package edu.stanford.nlp.util

Examples of edu.stanford.nlp.util.MetaClassTest$VarArgs


    String script =
      "local a = luajava.newInstance('"+B.class.getName()+"');\n" +
      "local b = a:set(a:get"+typename+"())\n" +
      "local c = a:setr(a:get"+typename+"())\n" +
      "return b,c";
    Varargs chunk = _G.get("loadstring").call(LuaValue.valueOf(script));
    if ( ! chunk.arg1().toboolean() )
      fail( chunk.arg(2).toString() );
    Varargs results = chunk.arg1().invoke();
    int nresults = results.narg();
    assertEquals( 2, nresults );
    LuaValue b = results.arg(1);
    LuaValue c = results.arg(2);
    String sb = b.tojstring();
    String sc = c.tojstring();
    assertEquals( "set("+typename+") "+value, sb );
    assertEquals( "setr("+typename+") "+value, sc );
  }
View Full Code Here


    public Object eval(ScriptContext context) throws ScriptException {
          Bindings b = context.getBindings(ScriptContext.ENGINE_SCOPE);
          LuaFunction f = newFunctionInstance();
          ClientBindings cb = new ClientBindings(b);
          f.setfenv(cb.env);
      Varargs result = f.invoke(LuaValue.NONE);
      cb.copyGlobalsToBindings();
      return result;
    }
View Full Code Here

        if ( !args.arg1().toboolean() )
          error( args.narg()>1? args.optjstring(2,"assertion failed!"): "assertion failed!" );
        return args;
      case 1: // "dofile", // ( filename ) -> result1, ...
      {
        Varargs v = args.isnil(1)?
            BaseLib.loadStream( baselib.STDIN, "=stdin" ):
            BaseLib.loadFile( args.checkjstring(1) );
        return v.isnil(1)? error(v.tojstring(2)): v.arg1().invoke();
      }
      case 2: // "getfenv", // ( [f] ) -> env
      {
        LuaValue f = getfenvobj(args.arg1());
          LuaValue e = f.getfenv();
        return e!=null? e: NIL;
      }
      case 3: // "getmetatable", // ( object ) -> table
      {
        LuaValue mt = args.checkvalue(1).getmetatable();
        return mt!=null? mt.rawget(METATABLE).optvalue(mt): NIL;
      }
      case 4: // "load", // ( func [,chunkname] ) -> chunk | nil, msg
      {
        LuaValue func = args.checkfunction(1);
        String chunkname = args.optjstring(2, "function");
        return BaseLib.loadStream(new StringInputStream(func), chunkname);
      }
      case 5: // "loadfile", // ( [filename] ) -> chunk | nil, msg
      {
        return args.isnil(1)?
          BaseLib.loadStream( baselib.STDIN, "stdin" ):
          BaseLib.loadFile( args.checkjstring(1) );
      }
      case 6: // "loadstring", // ( string [,chunkname] ) -> chunk | nil, msg
      {
        LuaString script = args.checkstring(1);
        String chunkname = args.optjstring(2, "string");
        return BaseLib.loadStream(script.toInputStream(),chunkname);
      }
      case 7: // "pcall", // (f, arg1, ...) -> status, result1, ...
      {
        LuaValue func = args.checkvalue(1);
        LuaThread.onCall(this);
        try {
          return pcall(func,args.subargs(2),null);
        } finally {
          LuaThread.onReturn();
        }
      }
      case 8: // "xpcall", // (f, err) -> result1, ...       
      {
        LuaThread.onCall(this);
        try {
          return pcall(args.arg1(),NONE,args.checkvalue(2));
        } finally {
          LuaThread.onReturn();
        }
      }
      case 9: // "print", // (...) -> void
      {
        LuaValue tostring = LuaThread.getGlobals().get("tostring");
        for ( int i=1, n=args.narg(); i<=n; i++ ) {
          if ( i>1 ) baselib.STDOUT.write( '\t' );
          LuaString s = tostring.call( args.arg(i) ).strvalue();
          int z = s.indexOf((byte)0, 0);
          baselib.STDOUT.write( s.m_bytes, s.m_offset, z>=0? z: s.m_length );
        }
        baselib.STDOUT.println();
        return NONE;
      }
      case 10: // "select", // (f, ...) -> value1, ...
      {
        int n = args.narg()-1;        
        if ( args.arg1().equals(valueOf("#")) )
          return valueOf(n);
        int i = args.checkint(1);
        if ( i == 0 || i < -n )
          argerror(1,"index out of range");
        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() )
          return h.call(arg);
        LuaValue v = arg.tostring();
        if ( ! v.isnil() )
          return v;
        return valueOf(arg.tojstring());
      }
      case 18: { // "tonumber", // (e [,base]) -> value
        LuaValue arg1 = args.checkvalue(1);
View Full Code Here

      case NEWINSTANCE:
      case NEW: {
        // get constructor
        final LuaValue c = args.checkvalue(1);
        final Class clazz = (opcode==NEWINSTANCE? classForName(c.tojstring()): (Class) c.checkuserdata(Class.class));
        final Varargs consargs = args.subargs(2);
        return JavaClass.forClass(clazz).getConstructor().invoke(consargs);
      }
       
      case CREATEPROXY: {       
        final int niface = args.narg()-1;
View Full Code Here

      if ( q >= 0 ) {
        filename = template.substring(0,q) + name + template.substring(q+1);
      }
     
      // try loading the file
      Varargs v = BaseLib.loadFile(filename);
      if ( v.arg1().isfunction() )
        return v.arg1();
     
      // report error
      if ( sb == null )
        sb = new StringBuffer();
      sb.append( "\n\t'"+filename+"': "+v.arg(2) );
    }
    return valueOf(sb.toString());
  }
View Full Code Here

        cl.opcode = WRAPPED;
        return cl;
      }
      case WRAPPED: {
        final LuaThread t = (LuaThread) env;
        final Varargs result = t.resume( args );
        if ( result.arg1().toboolean() ) {
          return result.subargs(2);
        } else {
          error( result.arg(2).tojstring() );
        }
      }
      default:
        return NONE;
    }
View Full Code Here

      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);
           list.append(v);
         }
      }       
      return LuaValue.varargsOf(new LuaValue[] {list});
    }
View Full Code Here

      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);
           map.put(k, v);
         }
      }       
      return LuaValue.varargsOf(new LuaValue[] {map});
    }
View Full Code Here

  public static LuaTable onCCWrappedILuaObject(final LuaTable table, final ILuaObject object) {
    if(object instanceof CCCommandWrapper) {
      LuaTable lpTable = new LPLuaTable((CCCommandWrapper)object);
      LuaValue k = LuaValue.NIL;
      while(true) {
        Varargs n = table.next(k);
        if((k = n.arg1()).isnil()) break;
        LuaValue v = n.arg(2);
        lpTable.set(k, v);
      }
      ((CCCommandWrapper)object).table = lpTable;
      return lpTable;
    }
View Full Code Here

                Position pos = new Position(entityTable.get("position").get(1).checkint(), entityTable.get("position").get(2).checkint());
                int colour = entityTable.get("colour").checkint();
                boolean collidable = entityTable.get("collidable").checkboolean();

                Entity ent = level.createEntity(a.toString(), new Entity(pos, chr, colour, collidable));
                Varargs entTable = LuaLevel.this.luaEntityTable(a.toString(), ent);

                final String[] events = new String[]{"behavior", "onEntityCollision"};

                for (String ev : events) {
                    if (entityTable.get(ev) != NIL) {
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.util.MetaClassTest$VarArgs

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.