Package org.luaj.vm2

Examples of org.luaj.vm2.Prototype


     this.strings = strings;
  }
 
  /** Load into a Closure or LuaFunction, with the supplied initial environment */
  public LuaFunction load(InputStream stream, String name, LuaValue env) throws IOException {
    Prototype p = compile( stream, name );
    return new LuaClosure( p, env );
  }
View Full Code Here


  public Hashtable compileAll(InputStream script, String chunkname, String filename) throws IOException {
    String classname = toStandardJavaClassName( chunkname );
    String luaname = toStandardLuaFileName( filename );
    Hashtable h = new Hashtable();
    Prototype p = LuaC.instance.compile(script, classname);
    JavaGen gen = new JavaGen(p, classname, luaname);
    insert( h, gen );
    return h;
  }
View Full Code Here

    for ( int i=0, n=gen.inners!=null? gen.inners.length: 0; i<n; i++ )
      insert(h, gen.inners[i]);
  }

  public LuaFunction load(InputStream stream, String name, LuaValue env) throws IOException {
    Prototype p = LuaC.instance.compile(stream, name);
    String classname = toStandardJavaClassName( name );
    String luaname = toStandardLuaFileName( name );
    JavaLoader loader = new JavaLoader(env);
    return loader.load(p, classname, luaname);
  }
View Full Code Here

            String path = jar + dir + "/" + file;
            byte[] lua = bytesFromJar(path);

            // compile in memory
            InputStream is = new ByteArrayInputStream(lua);
            Prototype p = LuaC.instance.compile(is, "@" + dir + "/" + file);
            String actual = protoToString(p);

            // load expected value from jar
            byte[] luac = bytesFromJar(path + "c");
            Prototype e = loadFromBytes(luac, file);
            String expected = protoToString(e);

            // compare results
            assertEquals(expected, actual);

            // dump into memory
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DumpState.dump(p, baos, false);
            byte[] dumped = baos.toByteArray();

            // re-undump
            Prototype p2 = loadFromBytes(dumped, file);
            String actual2 = protoToString(p2);

            // compare again
            assertEquals(actual, actual2);
View Full Code Here

   
    // propogate to inner prototypes
    for ( int pc=0; pc<n; pc++ ) {
      if ( Lua.GET_OPCODE(code[pc]) == Lua.OP_CLOSURE ) {
        int bx = Lua.GETARG_Bx(code[pc]);
        Prototype newp = prototype.p[bx];
        UpvalInfo[] newu = newp.nups>0? new UpvalInfo[newp.nups]: null;
        String newname = name + "$" + bx;
        for ( int j=0; j<newp.nups; ++j ) {
          int i = code[++pc];
          int b = Lua.GETARG_B(i);
View Full Code Here

      String script, String expectedPriorDump, String expectedPostDump, boolean shouldPass ) {
        try {
           
            // compile into prototype
            InputStream is = new ByteArrayInputStream(script.getBytes());
            Prototype p = LuaC.instance.compile(is, "script");
           
            // double check script result before dumping
            LuaFunction f = new LuaClosure(p, _G);
            LuaValue r = f.call();
            String actual = r.tojstring();
View Full Code Here

    if (this.htable.containsKey(v)) {
      idx = ((Integer) htable.get(v)).intValue();
    } else {
      idx = this.nk;
      this.htable.put(v, new Integer(idx));
      final Prototype f = this.f;
      if (f.k == null || nk + 1 >= f.k.length)
        f.k = realloc( f.k, nk*2 + 1 );
      f.k[this.nk++] = v;
    }
    return idx;
View Full Code Here

    this.f.lineinfo[this.pc - 1] = line;
  }


  int code(int instruction, int line) {
    Prototype f = this.f;
    this.dischargejpc(); /* `pc' will change */
    /* put new instruction in code array */
    if (f.code == null || this.pc + 1 > f.code.length)
      f.code = LuaC.realloc(f.code, this.pc * 2 + 1);
    f.code[this.pc] = instruction;
View Full Code Here

        InputStream ris = new Utf8Encoder(reader);
        try {
          final LuaFunction f = LoadState.load(ris, "script", null);
          if ( f.isclosure() ) {
            // most compiled functions are closures with prototypes
            final Prototype p = f.checkclosure().p;
          return new CompiledScriptImpl() {
            protected LuaFunction newFunctionInstance() {
              return new LuaClosure( p, null );
            }
          };
View Full Code Here

  }

 
  int registerlocalvar(LuaString varname) {
    FuncState fs = this.fs;
    Prototype f = fs.f;
    if (f.locvars == null || fs.nlocvars + 1 > f.locvars.length)
      f.locvars = LuaC.realloc( f.locvars, fs.nlocvars*2+1 );
    f.locvars[fs.nlocvars] = new LocVars(varname,0,0);
    return fs.nlocvars++;
  }
View Full Code Here

TOP

Related Classes of org.luaj.vm2.Prototype

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.