Package org.luaj.vm2

Examples of org.luaj.vm2.Varargs$SubVarargs


            }
        });
        globals.set("unpack", new unpack());

        // math.log10 got removed in 5.2
        LuaValue math = globals.get("math");
        math.set("log10", new OneArgFunction() {
            @Override
            public LuaValue call(LuaValue luaValue) {
                return valueOf(Math.log10(luaValue.checkdouble()));
            }
        });

        // table.maxn got removed in 5.2
        LuaValue table = globals.get("table");
        table.set("maxn", new OneArgFunction() {
            @Override public LuaValue call(LuaValue arg) {
                // TODO: is this correct?
                return arg.checktable().len();
            }
        });
View Full Code Here


            return LuaValue.valueOf(replace(msg, params));
        }

        private String replace(String msg, LuaTable params) {
            for (int i=1; i<params.length()+1; i++) {
                LuaValue param = params.get(i);
                String actualParam;
                if (param.istable()) {

                    if (!param.get("raw").isnil()) {
                        actualParam = param.get("raw").checkjstring();
                    } else if (!param.get("num").isnil()) {
                        if (param.get("num").isnumber()) {
                            LuaNumber number = param.get("num").checknumber();
                            NumberFormat nf = NumberFormat.getInstance(Locale.forLanguageTag(lang));
                            actualParam = nf.format(number.todouble());
                        } else {
                            actualParam = param.get("num").tojstring();
                        }
                    } else {
                        actualParam = "unknown";
                    }
                } else {
                    actualParam = param.checkjstring();
                }
                msg = msg.replace("$"+i, actualParam);
            }
            return msg;
        }
View Full Code Here

         * @param $interwiki    string Interwiki code
         */
        return new LibFunction() {
            @Override
            public Varargs invoke(Varargs args) {
                LuaValue ns    = args.arg(1);
                LuaValue title = args.arg(2);
                LuaValue fragment = args.arg(3);
                LuaValue interwiki = args.arg(4);
                return title(ns, title, fragment, interwiki);
            }
        };
    }
View Full Code Here

                // Traverse the directions table.
                LuaValue key = LuaValue.NIL;
                while (true) {

                    Varargs keyValue = directionsTable.next(key);
                    key = keyValue.arg1();
                    if (key.isnil()) {
                        break;
                    }
                    LuaValue directionTable = keyValue.arg(2);

                    int x = directionTable.get("x").checkint();
                    int y = directionTable.get("y").checkint();
                    int frameWidth = directionTable.get("frame_width").checkint();
                    int frameHeight = directionTable.get("frame_height").checkint();
View Full Code Here

        final int testCount        = tests.get("count").toint();
        final LuaValue provideFunc = tests.get("provide");
        final LuaValue runFunc     = tests.get("run");

        for (int i=1; i<testCount+1; i++) {
            final Varargs provideValue = provideFunc.invoke(valueOf(i));
            final LuaValue name = provideValue.arg(2);
            final String expected = provideValue.arg(3).checkjstring();

            Description testDescription = Description.createTestDescription(getClass(), name.toString());

            if (isIgnored(testDescription)) {
                notifier.fireTestIgnored(testDescription);
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

      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 void testExceptionMessage() {
    String script = "local c = luajava.bindClass( \""+SomeClass.class.getName()+"\" )\n" +
        "return pcall( c.someMethod, c )";
    Varargs vresult = _G.get("loadstring").call(LuaValue.valueOf(script)).invoke(LuaValue.NONE);
    LuaValue status = vresult.arg1();
    LuaValue message = vresult.arg(2);
    assertEquals( LuaValue.FALSE, status );   
    int index = message.toString().indexOf( "this is some message" );
    assertTrue( "bad message: "+message, index>=0 );   
  }
View Full Code Here

TOP

Related Classes of org.luaj.vm2.Varargs$SubVarargs

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.