/** Load a lua strin gvalue from the input stream * @return the {@link LuaString} value laoded. **/ LuaString loadString() throws IOException { int size = this.luacSizeofSizeT == 8? (int) loadInt64(): loadInt(); if ( size == 0 ) return null; byte[] bytes = new byte[size]; is.readFully( bytes, 0, size ); return LuaString.valueUsing( bytes, 0, bytes.length - 1 ); }
/** * Load the debug info for a function prototype * @param f the function Prototype * @throws IOException if there is an i/o exception */ void loadDebug( Prototype f ) throws IOException { f.source = loadString(); f.lineinfo = loadIntArray(); int n = loadInt(); f.locvars = n>0? new LocVars[n]: NOLOCVARS; for ( int i=0; i<n; i++ ) { LuaString varname = loadString(); int startpc = loadInt(); int endpc = loadInt(); f.locvars[i] = new LocVars(varname, startpc, endpc); } n = loadInt(); for ( int i=0; i<n; i++ ) f.upvalues[i].name = loadString(); }
/** Load a lua strin gvalue from the input stream * @return the {@link LuaString} value laoded. **/ LuaString loadString() throws IOException { int size = this.luacSizeofSizeT == 8? (int) loadInt64(): loadInt(); if ( size == 0 ) return null; byte[] bytes = new byte[size]; is.readFully( bytes, 0, size ); return LuaString.valueUsing( bytes, 0, bytes.length - 1 ); }
/** * Load the debug info for a function prototype * @param f the function Prototype * @throws IOException if there is an i/o exception */ void loadDebug( Prototype f ) throws IOException { f.source = loadString(); f.lineinfo = loadIntArray(); int n = loadInt(); f.locvars = n>0? new LocVars[n]: NOLOCVARS; for ( int i=0; i<n; i++ ) { LuaString varname = loadString(); int startpc = loadInt(); int endpc = loadInt(); f.locvars[i] = new LocVars(varname, startpc, endpc); } n = loadInt(); for ( int i=0; i<n; i++ ) f.upvalues[i].name = loadString(); }
/** * Load a number from a binary chunk * @return the {@link LuaValue} loaded * @throws IOException if an i/o exception occurs */ LuaValue loadNumber() throws IOException { if ( luacNumberFormat == NUMBER_FORMAT_INTS_ONLY ) { return LuaInteger.valueOf( loadInt() ); } else { return longBitsToLuaNumber( loadInt64() ); } }
/** * Load a function prototype from the input stream * @param p name of the source * @return {@link Prototype} instance that was loaded * @throws IOException */ public Prototype loadFunction(LuaString p) throws IOException { Prototype f = new Prototype(); //// this.L.push(f); // f.source = loadString(); // if ( f.source == null ) // f.source = p; f.linedefined = loadInt(); f.lastlinedefined = loadInt(); f.numparams = is.readUnsignedByte(); f.is_vararg = is.readUnsignedByte(); f.maxstacksize = is.readUnsignedByte(); f.code = loadIntArray(); loadConstants(f); loadUpvalues(f); loadDebug(f); // TODO: add check here, for debugging purposes, I believe // see ldebug.c // IF (!luaG_checkcode(f), "bad code"); // this.L.pop(); return f; }
/** Load an array of int values from the input stream * @return the array of int values laoded. **/ int[] loadIntArray() throws IOException { int n = loadInt(); if ( n == 0 ) return NOINTS; // read all data at once int m = n << 2; if ( buf.length < m ) buf = new byte[m]; is.readFully(buf,0,m); int[] array = new int[n]; for ( int i=0, j=0; i<n; ++i, j+=4 ) array[i] = luacLittleEndian? (buf[j+3] << 24) | ((0xff & buf[j+2]) << 16) | ((0xff & buf[j+1]) << 8) | (0xff & buf[j+0]): (buf[j+0] << 24) | ((0xff & buf[j+1]) << 16) | ((0xff & buf[j+2]) << 8) | (0xff & buf[j+3]); return array; }
/** * Load a number from a binary chunk * @return the {@link LuaValue} loaded * @throws IOException if an i/o exception occurs */ LuaValue loadNumber() throws IOException { if ( luacNumberFormat == NUMBER_FORMAT_INTS_ONLY ) { return LuaInteger.valueOf( loadInt() ); } else { return longBitsToLuaNumber( loadInt64() ); } }
/** * Load a function prototype from the input stream * @param p name of the source * @return {@link Prototype} instance that was loaded * @throws IOException */ public Prototype loadFunction(LuaString p) throws IOException { Prototype f = new Prototype(); //// this.L.push(f); // f.source = loadString(); // if ( f.source == null ) // f.source = p; f.linedefined = loadInt(); f.lastlinedefined = loadInt(); f.numparams = is.readUnsignedByte(); f.is_vararg = is.readUnsignedByte(); f.maxstacksize = is.readUnsignedByte(); f.code = loadIntArray(); loadConstants(f); loadUpvalues(f); loadDebug(f); // TODO: add check here, for debugging purposes, I believe // see ldebug.c // IF (!luaG_checkcode(f), "bad code"); // this.L.pop(); return f; }
/** Load an array of int values from the input stream * @return the array of int values laoded. **/ int[] loadIntArray() throws IOException { int n = loadInt(); if ( n == 0 ) return NOINTS; // read all data at once int m = n << 2; if ( buf.length < m ) buf = new byte[m]; is.readFully(buf,0,m); int[] array = new int[n]; for ( int i=0, j=0; i<n; ++i, j+=4 ) array[i] = luacLittleEndian? (buf[j+3] << 24) | ((0xff & buf[j+2]) << 16) | ((0xff & buf[j+1]) << 8) | (0xff & buf[j+0]): (buf[j+0] << 24) | ((0xff & buf[j+1]) << 16) | ((0xff & buf[j+2]) << 8) | (0xff & buf[j+3]); return array; }
void loadUpvalues(Prototype f) throws IOException { int n = loadInt(); f.upvalues = n>0? new Upvaldesc[n]: NOUPVALDESCS; for (int i=0; i<n; i++) { boolean instack = is.readByte() != 0; int idx = ((int) is.readByte()) & 0xff; f.upvalues[i] = new Upvaldesc(null, instack, idx); } }
void loadUpvalues(Prototype f) throws IOException { int n = loadInt(); f.upvalues = n>0? new Upvaldesc[n]: NOUPVALDESCS; for (int i=0; i<n; i++) { boolean instack = is.readByte() != 0; int idx = ((int) is.readByte()) & 0xff; f.upvalues[i] = new Upvaldesc(null, instack, idx); } }