aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-07-12 16:34:03 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-07-12 16:34:03 -0300
commit9f25df02d53f6d31d904957bc411ef72d8378dc8 (patch)
treef03105ea6d9bc5f6c9ac0ebeff6d3a3f48479637
parentae1cf64348ca7bcb6d3abb19a0b97918e343914c (diff)
downloadlua-9f25df02d53f6d31d904957bc411ef72d8378dc8.tar.gz
lua-9f25df02d53f6d31d904957bc411ef72d8378dc8.tar.bz2
lua-9f25df02d53f6d31d904957bc411ef72d8378dc8.zip
new definition for headers of binary files
-rw-r--r--ldo.c6
-rw-r--r--lundump.c14
-rw-r--r--lundump.h5
3 files changed, 9 insertions, 16 deletions
diff --git a/ldo.c b/ldo.c
index c2d0e92d..874a22b8 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.135 2001/06/05 19:27:32 roberto Exp roberto $ 2** $Id: ldo.c,v 1.136 2001/06/08 19:00:57 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -243,7 +243,7 @@ LUA_API int lua_loadfile (lua_State *L, const l_char *filename) {
243 int nlevel; /* level on the stack of filename */ 243 int nlevel; /* level on the stack of filename */
244 FILE *f = (filename == NULL) ? stdin : fopen(filename, l_s("r")); 244 FILE *f = (filename == NULL) ? stdin : fopen(filename, l_s("r"));
245 if (f == NULL) return LUA_ERRFILE; /* unable to open file */ 245 if (f == NULL) return LUA_ERRFILE; /* unable to open file */
246 bin = (ungetc(fgetc(f), f) == ID_CHUNK); 246 bin = (ungetc(fgetc(f), f) == LUA_SIGNATURE[0]);
247 if (bin && f != stdin) { 247 if (bin && f != stdin) {
248 fclose(f); 248 fclose(f);
249 f = fopen(filename, l_s("rb")); /* reopen in binary mode */ 249 f = fopen(filename, l_s("rb")); /* reopen in binary mode */
@@ -269,7 +269,7 @@ LUA_API int lua_loadbuffer (lua_State *L, const l_char *buff, size_t size,
269 int status; 269 int status;
270 if (!name) name = l_s("?"); 270 if (!name) name = l_s("?");
271 luaZ_mopen(&z, buff, size, name); 271 luaZ_mopen(&z, buff, size, name);
272 status = protectedparser(L, &z, buff[0]==ID_CHUNK); 272 status = protectedparser(L, &z, buff[0]==LUA_SIGNATURE[0]);
273 return status; 273 return status;
274} 274}
275 275
diff --git a/lundump.c b/lundump.c
index f365b577..0e09513c 100644
--- a/lundump.c
+++ b/lundump.c
@@ -165,8 +165,7 @@ static void LoadConstants (lua_State* L, Proto* f, ZIO* Z, int swap)
165 n=LoadInt(L,Z,swap); 165 n=LoadInt(L,Z,swap);
166 f->p=luaM_newvector(L,n,Proto*); 166 f->p=luaM_newvector(L,n,Proto*);
167 f->sizep=n; 167 f->sizep=n;
168 for (i=0; i<n; i++) 168 for (i=0; i<n; i++) f->p[i]=LoadFunction(L,Z,swap);
169 f->p[i]=LoadFunction(L,Z,swap);
170} 169}
171 170
172static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap) 171static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap)
@@ -190,7 +189,7 @@ static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap)
190 189
191static void LoadSignature (lua_State* L, ZIO* Z) 190static void LoadSignature (lua_State* L, ZIO* Z)
192{ 191{
193 const l_char* s=l_s(SIGNATURE); 192 const l_char* s=l_s(LUA_SIGNATURE);
194 while (*s!=0 && ezgetc(L,Z)==*s) 193 while (*s!=0 && ezgetc(L,Z)==*s)
195 ++s; 194 ++s;
196 if (*s!=0) luaO_verror(L,l_s("bad signature in `%.99s'"),ZNAME(Z)); 195 if (*s!=0) luaO_verror(L,l_s("bad signature in `%.99s'"),ZNAME(Z));
@@ -245,16 +244,11 @@ static Proto* LoadChunk (lua_State* L, ZIO* Z)
245 244
246/* 245/*
247** load one chunk from a file or buffer 246** load one chunk from a file or buffer
248** return main if ok and NULL at EOF
249*/ 247*/
250Proto* luaU_undump (lua_State* L, ZIO* Z) 248Proto* luaU_undump (lua_State* L, ZIO* Z)
251{ 249{
252 Proto* f=NULL; 250 Proto* f=LoadChunk(L,Z);
253 int c=zgetc(Z); 251 if (zgetc(Z)!=EOZ)
254 if (c==ID_CHUNK)
255 f=LoadChunk(L,Z);
256 c=zgetc(Z);
257 if (c!=EOZ)
258 luaO_verror(L,l_s("`%.99s' apparently contains more than one chunk"),ZNAME(Z)); 252 luaO_verror(L,l_s("`%.99s' apparently contains more than one chunk"),ZNAME(Z));
259 return f; 253 return f;
260} 254}
diff --git a/lundump.h b/lundump.h
index 267326e1..b82f0b8c 100644
--- a/lundump.h
+++ b/lundump.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.h,v 1.23 2001/06/28 13:55:17 lhf Exp $ 2** $Id: lundump.h,v 1.23 2001/06/28 13:55:17 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,8 +19,7 @@ int luaU_endianness (void);
19/* definitions for headers of binary files */ 19/* definitions for headers of binary files */
20#define VERSION 0x41 /* last format change was in 4.1 */ 20#define VERSION 0x41 /* last format change was in 4.1 */
21#define VERSION0 0x41 /* last major change was in 4.1 */ 21#define VERSION0 0x41 /* last major change was in 4.1 */
22#define ID_CHUNK 27 /* binary files start with ESC... */ 22#define LUA_SIGNATURE "\033Lua" /* binary files start with <esc>Lua */
23#define SIGNATURE "Lua" /* ...followed by this signature */
24 23
25/* a multiple of PI for testing native format */ 24/* a multiple of PI for testing native format */
26/* multiplying by 1E8 gives non-trivial integer values */ 25/* multiplying by 1E8 gives non-trivial integer values */