aboutsummaryrefslogtreecommitdiff
path: root/lundump.c
diff options
context:
space:
mode:
Diffstat (limited to 'lundump.c')
-rw-r--r--lundump.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/lundump.c b/lundump.c
index ffc8853b..f5d6fcf9 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 2.37 2014/04/29 18:14:16 roberto Exp roberto $ 2** $Id: lundump.c,v 2.38 2014/06/18 13:19:17 roberto Exp roberto $
3** load precompiled Lua chunks 3** load precompiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -31,7 +31,6 @@ typedef struct {
31 ZIO *Z; 31 ZIO *Z;
32 Mbuffer *b; 32 Mbuffer *b;
33 const char *name; 33 const char *name;
34 TString *source; /* source (the same for all prototypes) */
35} LoadState; 34} LoadState;
36 35
37 36
@@ -106,12 +105,12 @@ static void LoadCode (LoadState *S, Proto *f) {
106} 105}
107 106
108 107
109static void LoadFunction(LoadState *S, Proto *f); 108static void LoadFunction(LoadState *S, Proto *f, TString *psource);
110 109
111 110
112static void LoadConstants (LoadState *S, Proto *f) { 111static void LoadConstants (LoadState *S, Proto *f) {
113 int i, n; 112 int i;
114 n = LoadInt(S); 113 int n = LoadInt(S);
115 f->k = luaM_newvector(S->L, n, TValue); 114 f->k = luaM_newvector(S->L, n, TValue);
116 f->sizek = n; 115 f->sizek = n;
117 for (i = 0; i < n; i++) 116 for (i = 0; i < n; i++)
@@ -140,14 +139,19 @@ static void LoadConstants (LoadState *S, Proto *f) {
140 lua_assert(0); 139 lua_assert(0);
141 } 140 }
142 } 141 }
143 n = LoadInt(S); 142}
143
144
145static void LoadProtos (LoadState *S, Proto *f) {
146 int i;
147 int n = LoadInt(S);
144 f->p = luaM_newvector(S->L, n, Proto *); 148 f->p = luaM_newvector(S->L, n, Proto *);
145 f->sizep = n; 149 f->sizep = n;
146 for (i = 0; i < n; i++) 150 for (i = 0; i < n; i++)
147 f->p[i] = NULL; 151 f->p[i] = NULL;
148 for (i = 0; i < n; i++) { 152 for (i = 0; i < n; i++) {
149 f->p[i] = luaF_newproto(S->L); 153 f->p[i] = luaF_newproto(S->L);
150 LoadFunction(S, f->p[i]); 154 LoadFunction(S, f->p[i], f->source);
151 } 155 }
152} 156}
153 157
@@ -168,7 +172,6 @@ static void LoadUpvalues (LoadState *S, Proto *f) {
168 172
169static void LoadDebug (LoadState *S, Proto *f) { 173static void LoadDebug (LoadState *S, Proto *f) {
170 int i, n; 174 int i, n;
171 f->source = S->source;
172 n = LoadInt(S); 175 n = LoadInt(S);
173 f->lineinfo = luaM_newvector(S->L, n, int); 176 f->lineinfo = luaM_newvector(S->L, n, int);
174 f->sizelineinfo = n; 177 f->sizelineinfo = n;
@@ -189,7 +192,10 @@ static void LoadDebug (LoadState *S, Proto *f) {
189} 192}
190 193
191 194
192static void LoadFunction (LoadState *S, Proto *f) { 195static void LoadFunction (LoadState *S, Proto *f, TString *psource) {
196 f->source = LoadString(S);
197 if (f->source == NULL) /* no source in dump? */
198 f->source = psource; /* reuse parent's source */
193 f->linedefined = LoadInt(S); 199 f->linedefined = LoadInt(S);
194 f->lastlinedefined = LoadInt(S); 200 f->lastlinedefined = LoadInt(S);
195 f->numparams = LoadByte(S); 201 f->numparams = LoadByte(S);
@@ -198,6 +204,7 @@ static void LoadFunction (LoadState *S, Proto *f) {
198 LoadCode(S, f); 204 LoadCode(S, f);
199 LoadConstants(S, f); 205 LoadConstants(S, f);
200 LoadUpvalues(S, f); 206 LoadUpvalues(S, f);
207 LoadProtos(S, f);
201 LoadDebug(S, f); 208 LoadDebug(S, f);
202} 209}
203 210
@@ -259,8 +266,7 @@ Closure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff,
259 setclLvalue(L, L->top, cl); 266 setclLvalue(L, L->top, cl);
260 incr_top(L); 267 incr_top(L);
261 cl->l.p = luaF_newproto(L); 268 cl->l.p = luaF_newproto(L);
262 S.source = cl->l.p->source = LoadString(&S); /* read source */ 269 LoadFunction(&S, cl->l.p, NULL);
263 LoadFunction(&S, cl->l.p);
264 lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues); 270 lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues);
265 luai_verifycode(L, buff, cl->l.p); 271 luai_verifycode(L, buff, cl->l.p);
266 return cl; 272 return cl;