Examples of LuaValue


Examples of org.luaj.vm2.LuaValue

   
    final static String LUADIR = "lua";
   
    public static boolean init () {
    String script = LUADIR + "\\sv_init.lua";
        LuaValue _G = JsePlatform.standardGlobals();
        try {
            _G.get("dofile").call(LuaValue.valueOf(script));
           
        } catch (org.luaj.vm2.LuaError ex) {
            Main.ui.commitln("Error: " + ex.getMessage());
            Main.ui.commitln(sutil.ADVICE.REINSTALL.s());
            return true;
View Full Code Here

Examples of org.luaj.vm2.LuaValue

                }

                Vector<SpriteAnimationDirection> directions = new Vector<SpriteAnimationDirection>();

                // 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();
                    int originX = directionTable.get("origin_x").optint(0);
                    int originY = directionTable.get("origin_y").optint(0);
                    int numFrames = directionTable.get("num_frames").optint(1);
                    int numColumns = directionTable.get("num_columns").optint(numFrames);

                    Rectangle firstFrameRectangle = new Rectangle(x, y, frameWidth, frameHeight);

                    try {
                      SpriteAnimationDirection direction =  new SpriteAnimationDirection(
View Full Code Here

Examples of org.luaj.vm2.LuaValue

        params.put("b", "b_value");
        subject = new Frame(params, null);
    }

    @Test public void testGetAllArguments() {
        LuaValue arguments = subject.getAllArguments();
        assertThat(arguments.length()).isEqualTo(2);
        assertThat(arguments.get(1).toString()).isEqualTo("a_value");
        assertThat(arguments.get(2).toString()).isEqualTo("b_value");
    }
View Full Code Here

Examples of org.luaj.vm2.LuaValue

        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

Examples of org.luaj.vm2.LuaValue

    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

Examples of org.luaj.vm2.LuaValue

        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

Examples of org.luaj.vm2.LuaValue

        });
    }

    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

Examples of org.luaj.vm2.LuaValue

    }

    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

Examples of org.luaj.vm2.LuaValue

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

Examples of org.luaj.vm2.LuaValue

            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
TOP
Copyright © 2018 www.massapi.com. 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.