Package org.luaj.vm2

Examples of org.luaj.vm2.LuaFunction


    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,10);
    table.setmetatable(meta);
    table.set("size", new len());
    table.set("set_size", new set_size());
   
    new getint(table, 0, "get_int16");
    new getint(table, 1, "get_int32");
    new getint(table, 2, "get_int64");

    new setint(table, 0, "set_int16");
    new setint(table, 1, "set_int32");
    new setint(table, 2, "set_int64");
   
    table.set("set_string", new set_string());
    table.set("set_bytes", new set_bytes());

    table.set("get_type", new get_type());
    table.set("set_type", new set_type());

    instance.registerPackage("bytes", table);
    return table;
  }
View Full Code Here


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

    public LuaValue call(LuaValue env) {
      LuaTable meta = new LuaTable(0, 5);
      meta.set("__len", new len());
      meta.set("__tostring", new tostring());
      meta.set("__index", new index());
      meta.set("__newindex", new newindex());
     
      instance.registerPackage("Bytes", meta);
      return meta;
    }
View Full Code Here

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

  public LuaValue call(LuaValue env) {   
    LuaTable meta = new LuaTable();
    meta.set("__index", new index());
   
    LuaTable table = new LuaTable();   
    table.setmetatable(meta);
   
    instance.registerPackage("aerospike", table);   
    return table;
  }
View Full Code Here

  public LuaStreamLib(LuaInstance instance) {
    this.instance = instance;
  }
 
  public LuaValue call(LuaValue env) {
    LuaTable meta = new LuaTable(0,1);
    meta.set("__tostring", new tostring());
   
    LuaTable table = new LuaTable(0,10);
    table.setmetatable(meta);
    table.set("read", new read());
    table.set("readable", new readable());
    table.set("writeable", new writeable());
    table.set("write", new write());
   
    instance.registerPackage("stream", table);
    return table;
  }
View Full Code Here

   
    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

                }

                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

        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

        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

TOP

Related Classes of org.luaj.vm2.LuaFunction

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.