Package org.luaj.vm2.lib

Examples of org.luaj.vm2.lib.BaseLib$BaseLibV


        tests    = loadTests();
    }

    public void runTests(RunNotifier notifier)  {
        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);
                continue;
            }
View Full Code Here


    public String execute(String module, String method, Frame frame) throws IOException {
        String name = module;
        if (!name.startsWith(Importer.MODULE)) {
            name = Importer.MODULE + name;
        }
        LuaValue chunk = globals.load(findModule(module), name, "t", globals).call();
        LuaValue luaFunction = chunk.get(method);
        LuaValue executeFunction = globals.get("mw").get("executeFunction");

        if (luaFunction == null || luaFunction.isnil()) {
            throw new AssertionError("luaFunction is nil");
        }

        try {
            currentFrame = frame;
            return executeFunction.call(luaFunction).tojstring();
        } finally {
            currentFrame = null;
        }
    }
View Full Code Here

        fakeWikiBase();
    }

    private void stubExecuteModule() {
        // don't need module isolation
        final LuaValue mw = globals.get("mw");
        mw.set("executeModule", new TwoArgFunction() {
            @Override public LuaValue call(LuaValue chunk, LuaValue isConsole) {
                return chunk.call();
            }
        });
    }
View Full Code Here

        });
    }

    private void fakeWikiBase() {
        // fake http://www.mediawiki.org/wiki/Extension:Wikibase
        final LuaValue mw = globals.get("mw");
        final LuaTable wikibase = new LuaTable();
        wikibase.set("getEntity", new ZeroArgFunction() {
            @Override public LuaValue call() {
                return NIL;
            }
        });
        mw.set("wikibase", wikibase);
    }
View Full Code Here

    }

    private void load(MwInterface luaInterface) throws IOException {
        // logger.debug("loading interface " + luaInterface);

        LuaValue pkg = globals.loadfile(luaInterface.name()+
                (luaInterface.name().endsWith(".lua") ? "" : ".lua")).call();

        LuaValue setupInterface = pkg.get("setupInterface");

        if (!setupInterface.isnil()) {
            globals.set("mw_interface", luaInterface.getInterface());
            setupInterface.call(luaInterface.getSetupOptions());
        }
    }
View Full Code Here

            }
        });
        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

  public static final void putInstance(LuaInstance instance) {
    InstanceQueue.offer(instance);
  }
 
  public static final Prototype loadPackage(String packageName, boolean system) throws AerospikeException {
    Prototype prototype = Packages.get(packageName);
   
    if (prototype == null) {
      InputStream is = getInputStream(packageName, system);
      prototype = compile(packageName, is);
      Packages.put(packageName, prototype);
View Full Code Here

  public void load(String packageName, boolean system) throws AerospikeException {
    if (packageLib.loaded.get(packageName).toboolean()) {
      return;
    }
   
    Prototype prototype = LuaCache.loadPackage(packageName, system);
    LuaClosure function = new LuaClosure(prototype, globals);
    function.invoke();
   
    packageLib.loaded.set(packageName, globals);
  }
View Full Code Here

TOP

Related Classes of org.luaj.vm2.lib.BaseLib$BaseLibV

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.