void loadConstants(LPrototype f) throws IOException { int n = loadInt(); LValue[] values = new LValue[n]; for (int i = 0; i < n; i++) { switch (is.readByte()) { case Lua.LUA_TNIL: values[i] = LNil.NIL; break; case Lua.LUA_TBOOLEAN: values[i] = (0 != is.readUnsignedByte() ? LBoolean.TRUE : LBoolean.FALSE); break; case Lua.LUA_TINT: values[i] = LInteger.valueOf(loadInt()); break; case Lua.LUA_TNUMBER: values[i] = loadNumber(); break; case Lua.LUA_TSTRING: values[i] = loadString(); break; default: throw new IllegalStateException("bad constant"); } } f.k = values; n = loadInt(); LPrototype[] protos = new LPrototype[n]; for (int i = 0; i < n; i++) protos[i] = loadFunction(f.source); f.p = protos; }
void loadDebug(LPrototype f) throws IOException { f.lineinfo = loadIntArray(); int n = loadInt(); f.locvars = new LocVars[n]; for (int i = 0; i < n; i++) { LString varname = loadString(); int startpc = loadInt(); int endpc = loadInt(); f.locvars[i] = new LocVars(varname, startpc, endpc); } n = loadInt(); f.upvalues = new LString[n]; for (int i = 0; i < n; i++) { f.upvalues[i] = loadString(); } }
public LPrototype loadFunction(LString p) throws IOException { LPrototype f = new LPrototype(); // this.L.push(f); f.source = loadString(); if (f.source == null) f.source = p; f.linedefined = loadInt(); f.lastlinedefined = loadInt(); f.nups = is.readUnsignedByte(); f.numparams = is.readUnsignedByte(); f.is_vararg = is.readUnsignedByte(); f.maxstacksize = is.readUnsignedByte(); f.code = loadIntArray(); loadConstants(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; }