Package org.luaj.vm2.lib

Examples of org.luaj.vm2.lib.ZeroArgFunction


    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 LuaValue isSubsting() {
        return new ZeroArgFunction() {
            @Override public LuaValue call() {
                // TODO
                return FALSE;
            }
        };
View Full Code Here

            }
        };
    }

    private LuaValue incrementExpensiveFunctionCount() {
        return new ZeroArgFunction() {
            @Override public LuaValue call() {
                if (++expensiveFunctionCount > MAX_EXPENSIVE_CALLS) {
                    error("too many expensive function calls");
                }
                return NIL;
View Full Code Here

            }
        };
    }

    private LuaValue getContLangCode() {
        return new ZeroArgFunction() {
            @Override
            public LuaValue call() {
                return valueOf("en");
            }
        };
View Full Code Here

        table.set("getEntityTable", getEntityTable());
        return table;
    }

    private LuaValue getEntityTable() {
        return new ZeroArgFunction() {
            @Override
            public LuaValue call() {
                return NIL;
            }
        };
View Full Code Here

    _G.set("a", aaa);
    newenv.set("a", eee);

    // function tests
    {
      LuaFunction f = new ZeroArgFunction(_G) { public LuaValue call() { return env.get("a");}};
      assertEquals( aaa, f.call() );
      f.setfenv(newenv);
      assertEquals( newenv, f.getfenv() );
      assertEquals( eee, f.call() );
    }
   
    // closure tests
    {
      Prototype p = createPrototype( "return a\n", "closuretester" );
      LuaClosure c = new LuaClosure(p, _G);
      assertEquals( aaa, c.call() );
      c.setfenv(newenv);
      assertEquals( newenv, c.getfenv() );
      assertEquals( eee, c.call() );
    }

    // thread tests, functions created in threads inherit the thread's environment initially
    // those closures created not in any other function get the thread's enviroment
    Prototype p2 = createPrototype( "return loadstring('return a')", "threadtester" );
    {
      LuaThread t = new LuaThread(new LuaClosure(p2,_G), _G);
      Varargs v = t.resume(LuaValue.NONE);
      assertEquals(LuaValue.TRUE, v.arg(1) );
      LuaValue f = v.arg(2);
      assertEquals( LuaValue.TFUNCTION, f.type() );
      assertEquals( aaa, f.call() );
      assertEquals( _G, f.getfenv() );
    }
    {
      // change the thread environment after creation!
      LuaThread t = new LuaThread(new LuaClosure(p2,_G), _G);
      t.setfenv(newenv);
      Varargs v = t.resume(LuaValue.NONE);
      assertEquals(LuaValue.TRUE, v.arg(1) );
      LuaValue f = v.arg(2);
      assertEquals( LuaValue.TFUNCTION, f.type() );
      assertEquals( eee, f.call() );
      assertEquals( newenv, f.getfenv() );
    }
    {
      // let the closure have a different environment from the thread
      Prototype p3 = createPrototype( "return function() return a end", "envtester" );
      LuaThread t = new LuaThread(new LuaClosure(p3,newenv), _G);
      Varargs v = t.resume(LuaValue.NONE);
      assertEquals(LuaValue.TRUE, v.arg(1) );
      LuaValue f = v.arg(2);
      assertEquals( LuaValue.TFUNCTION, f.type() );
      assertEquals( eee, f.call() );
      assertEquals( newenv, f.getfenv() );
    }
  }
View Full Code Here

 
  private final Globals globals = new Globals();
  private final PackageLib packageLib;
 
  public LuaInstance() throws AerospikeException {
    globals.load(new JseBaseLib());
    packageLib = new PackageLib();
    globals.load(packageLib);
    //globals.load(new Bit32Lib()); // not needed for 5.1 compatibility 
    globals.load(new TableLib());
    globals.load(new StringLib());
View Full Code Here

    //globals.load(new Bit32Lib()); // not needed for 5.1 compatibility 
    globals.load(new TableLib());
    globals.load(new StringLib());
    globals.load(new CoroutineLib());
    globals.load(new JseMathLib());
    globals.load(new JseIoLib());
    globals.load(new JseOsLib());
    globals.load(new LuajavaLib());
    globals.load(new DebugLib());
    globals.load(new LuaBytesLib(this));
    globals.load(new LuaListLib(this));
View Full Code Here

    globals.load(packageLib);
    //globals.load(new Bit32Lib()); // not needed for 5.1 compatibility 
    globals.load(new TableLib());
    globals.load(new StringLib());
    globals.load(new CoroutineLib());
    globals.load(new JseMathLib());
    globals.load(new JseIoLib());
    globals.load(new JseOsLib());
    globals.load(new LuajavaLib());
    globals.load(new DebugLib());
    globals.load(new LuaBytesLib(this));
View Full Code Here

    globals.load(new TableLib());
    globals.load(new StringLib());
    globals.load(new CoroutineLib());
    globals.load(new JseMathLib());
    globals.load(new JseIoLib());
    globals.load(new JseOsLib());
    globals.load(new LuajavaLib());
    globals.load(new DebugLib());
    globals.load(new LuaBytesLib(this));
    globals.load(new LuaListLib(this));
    globals.load(new LuaMapLib(this));
View Full Code Here

TOP

Related Classes of org.luaj.vm2.lib.ZeroArgFunction

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.