Lines Matching refs:S
40 static l_noret error (LoadState *S, const char *why) { in error() argument
41 luaO_pushfstring(S->L, "%s: bad binary format (%s)", S->name, why); in error()
42 luaD_throw(S->L, LUA_ERRSYNTAX); in error()
50 #define loadVector(S,b,n) loadBlock(S,b,(n)*sizeof((b)[0])) argument
52 static void loadBlock (LoadState *S, void *b, size_t size) { in loadBlock() argument
53 if (luaZ_read(S->Z, b, size) != 0) in loadBlock()
54 error(S, "truncated chunk"); in loadBlock()
58 #define loadVar(S,x) loadVector(S,&x,1) argument
61 static lu_byte loadByte (LoadState *S) { in loadByte() argument
62 int b = zgetc(S->Z); in loadByte()
64 error(S, "truncated chunk"); in loadByte()
69 static size_t loadUnsigned (LoadState *S, size_t limit) { in loadUnsigned() argument
74 b = loadByte(S); in loadUnsigned()
76 error(S, "integer overflow"); in loadUnsigned()
83 static size_t loadSize (LoadState *S) { in loadSize() argument
84 return loadUnsigned(S, ~(size_t)0); in loadSize()
88 static int loadInt (LoadState *S) { in loadInt() argument
89 return cast_int(loadUnsigned(S, INT_MAX)); in loadInt()
93 static lua_Number loadNumber (LoadState *S) { in loadNumber() argument
95 loadVar(S, x); in loadNumber()
100 static lua_Integer loadInteger (LoadState *S) { in loadInteger() argument
102 loadVar(S, x); in loadInteger()
110 static TString *loadStringN (LoadState *S, Proto *p) { in loadStringN() argument
111 lua_State *L = S->L; in loadStringN()
113 size_t size = loadSize(S); in loadStringN()
118 loadVector(S, buff, size); /* load string into buffer */ in loadStringN()
125 loadVector(S, getstr(ts), size); /* load directly in final place */ in loadStringN()
136 static TString *loadString (LoadState *S, Proto *p) { in loadString() argument
137 TString *st = loadStringN(S, p); in loadString()
139 error(S, "bad format for constant string"); in loadString()
144 static void loadCode (LoadState *S, Proto *f) { in loadCode() argument
145 int n = loadInt(S); in loadCode()
146 f->code = luaM_newvectorchecked(S->L, n, Instruction); in loadCode()
148 loadVector(S, f->code, n); in loadCode()
152 static void loadFunction(LoadState *S, Proto *f, TString *psource);
155 static void loadConstants (LoadState *S, Proto *f) { in loadConstants() argument
157 int n = loadInt(S); in loadConstants()
158 f->k = luaM_newvectorchecked(S->L, n, TValue); in loadConstants()
164 int t = loadByte(S); in loadConstants()
176 setfltvalue(o, loadNumber(S)); in loadConstants()
179 setivalue(o, loadInteger(S)); in loadConstants()
183 setsvalue2n(S->L, o, loadString(S, f)); in loadConstants()
191 static void loadProtos (LoadState *S, Proto *f) { in loadProtos() argument
193 int n = loadInt(S); in loadProtos()
194 f->p = luaM_newvectorchecked(S->L, n, Proto *); in loadProtos()
199 f->p[i] = luaF_newproto(S->L); in loadProtos()
200 luaC_objbarrier(S->L, f, f->p[i]); in loadProtos()
201 loadFunction(S, f->p[i], f->source); in loadProtos()
212 static void loadUpvalues (LoadState *S, Proto *f) { in loadUpvalues() argument
214 n = loadInt(S); in loadUpvalues()
215 f->upvalues = luaM_newvectorchecked(S->L, n, Upvaldesc); in loadUpvalues()
220 f->upvalues[i].instack = loadByte(S); in loadUpvalues()
221 f->upvalues[i].idx = loadByte(S); in loadUpvalues()
222 f->upvalues[i].kind = loadByte(S); in loadUpvalues()
227 static void loadDebug (LoadState *S, Proto *f) { in loadDebug() argument
229 n = loadInt(S); in loadDebug()
230 f->lineinfo = luaM_newvectorchecked(S->L, n, ls_byte); in loadDebug()
232 loadVector(S, f->lineinfo, n); in loadDebug()
233 n = loadInt(S); in loadDebug()
234 f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo); in loadDebug()
237 f->abslineinfo[i].pc = loadInt(S); in loadDebug()
238 f->abslineinfo[i].line = loadInt(S); in loadDebug()
240 n = loadInt(S); in loadDebug()
241 f->locvars = luaM_newvectorchecked(S->L, n, LocVar); in loadDebug()
246 f->locvars[i].varname = loadStringN(S, f); in loadDebug()
247 f->locvars[i].startpc = loadInt(S); in loadDebug()
248 f->locvars[i].endpc = loadInt(S); in loadDebug()
250 n = loadInt(S); in loadDebug()
252 f->upvalues[i].name = loadStringN(S, f); in loadDebug()
256 static void loadFunction (LoadState *S, Proto *f, TString *psource) { in loadFunction() argument
257 f->source = loadStringN(S, f); in loadFunction()
260 f->linedefined = loadInt(S); in loadFunction()
261 f->lastlinedefined = loadInt(S); in loadFunction()
262 f->numparams = loadByte(S); in loadFunction()
263 f->is_vararg = loadByte(S); in loadFunction()
264 f->maxstacksize = loadByte(S); in loadFunction()
265 loadCode(S, f); in loadFunction()
266 loadConstants(S, f); in loadFunction()
267 loadUpvalues(S, f); in loadFunction()
268 loadProtos(S, f); in loadFunction()
269 loadDebug(S, f); in loadFunction()
273 static void checkliteral (LoadState *S, const char *s, const char *msg) { in checkliteral() argument
276 loadVector(S, buff, len); in checkliteral()
278 error(S, msg); in checkliteral()
282 static void fchecksize (LoadState *S, size_t size, const char *tname) { in fchecksize() argument
283 if (loadByte(S) != size) in fchecksize()
284 error(S, luaO_pushfstring(S->L, "%s size mismatch", tname)); in fchecksize()
288 #define checksize(S,t) fchecksize(S,sizeof(t),#t) argument
290 static void checkHeader (LoadState *S) { in checkHeader() argument
292 checkliteral(S, &LUA_SIGNATURE[1], "not a binary chunk"); in checkHeader()
293 if (loadByte(S) != LUAC_VERSION) in checkHeader()
294 error(S, "version mismatch"); in checkHeader()
295 if (loadByte(S) != LUAC_FORMAT) in checkHeader()
296 error(S, "format mismatch"); in checkHeader()
297 checkliteral(S, LUAC_DATA, "corrupted chunk"); in checkHeader()
298 checksize(S, Instruction); in checkHeader()
299 checksize(S, lua_Integer); in checkHeader()
300 checksize(S, lua_Number); in checkHeader()
301 if (loadInteger(S) != LUAC_INT) in checkHeader()
302 error(S, "integer format mismatch"); in checkHeader()
303 if (loadNumber(S) != LUAC_NUM) in checkHeader()
304 error(S, "float format mismatch"); in checkHeader()
312 LoadState S; in luaU_undump() local
315 S.name = name + 1; in luaU_undump()
317 S.name = "binary string"; in luaU_undump()
319 S.name = name; in luaU_undump()
320 S.L = L; in luaU_undump()
321 S.Z = Z; in luaU_undump()
322 checkHeader(&S); in luaU_undump()
323 cl = luaF_newLclosure(L, loadByte(&S)); in luaU_undump()
328 loadFunction(&S, cl->p, NULL); in luaU_undump()