aboutsummaryrefslogtreecommitdiff
path: root/lundump.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-10-25 18:30:41 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-10-25 18:30:41 -0300
commit671dc6eec24bc969bec22f7778386a4a19372f89 (patch)
treeaff3c1d51b7f6317da9eb9d41f729ac196cc0c10 /lundump.c
parente356a43dc0e6de6ee272188af0d37997b0adf635 (diff)
downloadlua-671dc6eec24bc969bec22f7778386a4a19372f89.tar.gz
lua-671dc6eec24bc969bec22f7778386a4a19372f89.tar.bz2
lua-671dc6eec24bc969bec22f7778386a4a19372f89.zip
new version (from lhf)
Diffstat (limited to 'lundump.c')
-rw-r--r--lundump.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/lundump.c b/lundump.c
index f4940239..d91d4508 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.54 2002/10/08 18:46:08 roberto Exp roberto $ 2** $Id: lundump.c,v 1.43 2002/08/07 00:36:03 lhf Exp lhf $
3** load pre-compiled Lua chunks 3** load pre-compiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -19,7 +19,7 @@
19typedef struct { 19typedef struct {
20 lua_State* L; 20 lua_State* L;
21 ZIO* Z; 21 ZIO* Z;
22 Mbuffer *buff; 22 Mbuffer* b;
23 int swap; 23 int swap;
24 const char* name; 24 const char* name;
25} LoadState; 25} LoadState;
@@ -46,7 +46,7 @@ static void LoadBlock (LoadState* S, void* b, size_t size)
46{ 46{
47 if (S->swap) 47 if (S->swap)
48 { 48 {
49 char *p=(char*) b+size-1; 49 char* p=(char*) b+size-1;
50 int n=size; 50 int n=size;
51 while (n--) *p--=(char)ezgetc(S); 51 while (n--) *p--=(char)ezgetc(S);
52 } 52 }
@@ -58,10 +58,10 @@ static void LoadVector (LoadState* S, void* b, int m, size_t size)
58{ 58{
59 if (S->swap) 59 if (S->swap)
60 { 60 {
61 char *q=(char*) b; 61 char* q=(char*) b;
62 while (m--) 62 while (m--)
63 { 63 {
64 char *p=q+size-1; 64 char* p=q+size-1;
65 int n=size; 65 int n=size;
66 while (n--) *p--=(char)ezgetc(S); 66 while (n--) *p--=(char)ezgetc(S);
67 q+=size; 67 q+=size;
@@ -100,7 +100,7 @@ static TString* LoadString (LoadState* S)
100 return NULL; 100 return NULL;
101 else 101 else
102 { 102 {
103 char* s=luaZ_openspace(S->L,S->buff,size); 103 char* s=luaZ_openspace(S->L,S->b,size);
104 ezread(S,s,size); 104 ezread(S,s,size);
105 return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ 105 return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
106 } 106 }
@@ -130,10 +130,10 @@ static void LoadLocals (LoadState* S, Proto* f)
130 130
131static void LoadLines (LoadState* S, Proto* f) 131static void LoadLines (LoadState* S, Proto* f)
132{ 132{
133 int n; 133 int size=LoadInt(S);
134 n=LoadInt(S); 134 f->lineinfo=luaM_newvector(S->L,size,int);
135 f->lineinfo=luaM_newvector(S->L,n,int); 135 f->sizelineinfo=size;
136 LoadVector(S,f->lineinfo,n,sizeof(*f->lineinfo)); 136 LoadVector(S,f->lineinfo,size,sizeof(*f->lineinfo));
137} 137}
138 138
139static Proto* LoadFunction (LoadState* S, TString* p); 139static Proto* LoadFunction (LoadState* S, TString* p);
@@ -233,8 +233,7 @@ static void LoadHeader (LoadState* S)
233 TESTSIZE(sizeof(lua_Number), "number"); 233 TESTSIZE(sizeof(lua_Number), "number");
234 x=LoadNumber(S); 234 x=LoadNumber(S);
235 if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */ 235 if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */
236 luaG_runerror(S->L,"unknown number format in %s: read %f; expected %f", 236 luaG_runerror(S->L,"unknown number format in %s",S->name);
237 S->name,x,tx);
238} 237}
239 238
240static Proto* LoadChunk (LoadState* S) 239static Proto* LoadChunk (LoadState* S)
@@ -244,12 +243,11 @@ static Proto* LoadChunk (LoadState* S)
244} 243}
245 244
246/* 245/*
247** load one chunk from a file or buffer 246** load precompiled chunk
248*/ 247*/
249Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer *buff) 248Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff)
250{ 249{
251 LoadState S; 250 LoadState S;
252 Proto* f;
253 const char* s=zname(Z); 251 const char* s=zname(Z);
254 if (*s=='@' || *s=='=') 252 if (*s=='@' || *s=='=')
255 S.name=s+1; 253 S.name=s+1;
@@ -259,11 +257,8 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer *buff)
259 S.name=s; 257 S.name=s;
260 S.L=L; 258 S.L=L;
261 S.Z=Z; 259 S.Z=Z;
262 S.buff=buff; 260 S.b=buff;
263 f=LoadChunk(&S); 261 return LoadChunk(&S);
264 if (zgetc(Z)!=EOZ)
265 luaG_runerror(L,"%s apparently contains more than one chunk",S.name);
266 return f;
267} 262}
268 263
269/* 264/*