Package org.luaj.vm2

Examples of org.luaj.vm2.LuaClosure.call()


    LuaTable _G = JsePlatform.standardGlobals();
   
    // compile into a chunk, or load as a class
    InputStream is =  new ByteArrayInputStream( script.getBytes() );
    LuaValue chunk = LuaC.instance.load(is, "script",_G);
    chunk.call();
  }

  private static void print(Prototype p) {
    System.out.println("--- "+p.is_vararg);
    Print.printCode(p);
View Full Code Here


      case 9: // "print", // (...) -> void
      {
        LuaValue tostring = LuaThread.getGlobals().get("tostring");
        for ( int i=1, n=args.narg(); i<=n; i++ ) {
          if ( i>1 ) baselib.STDOUT.write( '\t' );
          LuaString s = tostring.call( args.arg(i) ).strvalue();
          int z = s.indexOf((byte)0, 0);
          baselib.STDOUT.write( s.m_bytes, s.m_offset, z>=0? z: s.m_length );
        }
        baselib.STDOUT.println();
        return NONE;
View Full Code Here

      }
      case 17: { // "tostring", // (e) -> value
        LuaValue arg = args.checkvalue(1);
        LuaValue h = arg.metatag(TOSTRING);
        if ( ! h.isnil() )
          return h.call(arg);
        LuaValue v = arg.tostring();
        if ( ! v.isnil() )
          return v;
        return valueOf(arg.tojstring());
      }
View Full Code Here

      if ( loader.isnil() ) {
        error( "module '"+name+"' not found: "+name+sb );       
        }
           
        /* call loader with module name as argument */
      chunk = loader.call(name);
      if ( chunk.isfunction() )
        break;
      if ( chunk.isstring() )
        sb.append( chunk.tojstring() );
    }
View Full Code Here

        }
      };
      LuaTable loaders = _G.get("package").get("loaders").checktable();
      loaders.insert(1, loader);
      org.luaj.vm2.lib.BaseLib.instance.STDOUT = printStream;
      loader.call(LuaValue.valueOf(test)).invoke(LuaValue.valueOf(test));
    } finally {
      printStream.close();
    }
    return outputStream.toString();
  }
View Full Code Here

    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() );
    }
   
View Full Code Here

    {
      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" );
View Full Code Here

      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);
View Full Code Here

      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" );
View Full Code Here

      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

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.