/** * 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; }
int n = loadInt(); LuaValue[] values = n>0? new LuaValue[n]: NOVALUES; for ( int i=0; i<n; i++ ) { break; case LUA_TINT: values[i] = LuaInteger.valueOf( loadInt() ); break; case LUA_TNUMBER: values[i] = loadNumber(); break; case LUA_TSTRING: values[i] = loadString(); break; default: n = loadInt(); Prototype[] protos = n>0? new Prototype[n]: NOPROTOS; for ( int i=0; i<n; i++ ) protos[i] = loadFunction(f.source); f.p = protos;
/** * 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 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 ); }
String sname = getSourceName(chunkname); LoadState s = new LoadState( stream, sname ); s.loadHeader(); throw new LuaError("unsupported int size"); return s.loadFunction( LuaString.valueOf(sname) );
LoadState.install(sandboxedGlobals); LuaC.install(sandboxedGlobals);
String sname = getSourceName(chunkname); LoadState s = new LoadState( stream, sname ); s.loadHeader(); throw new LuaError("unsupported int size"); return s.loadFunction( LuaString.valueOf(sname) );
/** * Create a standard set of globals for JSE including all the libraries. * * @return Table of globals initialized with the standard JSE libraries * @see #debugGlobals() * @see org.luaj.vm2.lib.jse.JsePlatform * @see org.luaj.vm2.lib.jme.JmePlatform */ public static Globals standardGlobals() { Globals globals = new Globals(); globals.load(new JseBaseLib()); globals.load(new PackageLib()); globals.load(new Bit32Lib()); globals.load(new TableLib()); globals.load(new StringLib()); globals.load(new JseMathLib()); globals.load(new JseOsLib()); LoadState.install(globals); LuaC.install(globals); return globals; }
/** * 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 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; }
int n = loadInt(); LuaValue[] values = n>0? new LuaValue[n]: NOVALUES; for ( int i=0; i<n; i++ ) { break; case LUA_TINT: values[i] = LuaInteger.valueOf( loadInt() ); break; case LUA_TNUMBER: values[i] = loadNumber(); break; case LUA_TSTRING: values[i] = loadString(); break; default: n = loadInt(); Prototype[] protos = n>0? new Prototype[n]: NOPROTOS; for ( int i=0; i<n; i++ ) protos[i] = loadFunction(f.source); f.p = protos;
private Globals createLimitGlobals(){ Globals globals = new Globals(); globals.load(new JseBaseLib()); globals.load(new PackageLib()); globals.load(new Bit32Lib()); globals.load(new TableLib()); globals.load(new StringLib()); globals.load(new CoroutineLib()); globals.load(new JseMathLib()); globals.load(new JseOsLib()); globals.load(new LuajavaLib(RapidLuaLimitPath.msLimitArray, null)); LoadState.install(globals); LuaC.install(globals); return globals; }
/** * 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 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; }
/** * Create a standard set of globals for JSE including all the libraries. * * @return Table of globals initialized with the standard JSE libraries * @see #debugGlobals() * @see org.luaj.vm2.lib.jse.JsePlatform * @see org.luaj.vm2.lib.jme.JmePlatform */ public static Globals standardGlobals() { Globals globals = new Globals(); globals.load(new JseBaseLib()); globals.load(new PackageLib()); globals.load(new Bit32Lib()); 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()); LoadState.install(globals); LuaC.install(globals); return globals; }
/** 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; }