Skip to content

Commit

Permalink
new definition for headers of binary files
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-ieru committed Jul 12, 2001
1 parent ae1cf64 commit 9f25df0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
6 changes: 3 additions & 3 deletions ldo.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 1.135 2001/06/05 19:27:32 roberto Exp roberto $
** $Id: ldo.c,v 1.136 2001/06/08 19:00:57 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
Expand Down Expand Up @@ -243,7 +243,7 @@ LUA_API int lua_loadfile (lua_State *L, const l_char *filename) {
int nlevel; /* level on the stack of filename */
FILE *f = (filename == NULL) ? stdin : fopen(filename, l_s("r"));
if (f == NULL) return LUA_ERRFILE; /* unable to open file */
bin = (ungetc(fgetc(f), f) == ID_CHUNK);
bin = (ungetc(fgetc(f), f) == LUA_SIGNATURE[0]);
if (bin && f != stdin) {
fclose(f);
f = fopen(filename, l_s("rb")); /* reopen in binary mode */
Expand All @@ -269,7 +269,7 @@ LUA_API int lua_loadbuffer (lua_State *L, const l_char *buff, size_t size,
int status;
if (!name) name = l_s("?");
luaZ_mopen(&z, buff, size, name);
status = protectedparser(L, &z, buff[0]==ID_CHUNK);
status = protectedparser(L, &z, buff[0]==LUA_SIGNATURE[0]);
return status;
}

Expand Down
14 changes: 4 additions & 10 deletions lundump.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ static void LoadConstants (lua_State* L, Proto* f, ZIO* Z, int swap)
n=LoadInt(L,Z,swap);
f->p=luaM_newvector(L,n,Proto*);
f->sizep=n;
for (i=0; i<n; i++)
f->p[i]=LoadFunction(L,Z,swap);
for (i=0; i<n; i++) f->p[i]=LoadFunction(L,Z,swap);
}

static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap)
Expand All @@ -190,7 +189,7 @@ static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap)

static void LoadSignature (lua_State* L, ZIO* Z)
{
const l_char* s=l_s(SIGNATURE);
const l_char* s=l_s(LUA_SIGNATURE);
while (*s!=0 && ezgetc(L,Z)==*s)
++s;
if (*s!=0) luaO_verror(L,l_s("bad signature in `%.99s'"),ZNAME(Z));
Expand Down Expand Up @@ -245,16 +244,11 @@ static Proto* LoadChunk (lua_State* L, ZIO* Z)

/*
** load one chunk from a file or buffer
** return main if ok and NULL at EOF
*/
Proto* luaU_undump (lua_State* L, ZIO* Z)
{
Proto* f=NULL;
int c=zgetc(Z);
if (c==ID_CHUNK)
f=LoadChunk(L,Z);
c=zgetc(Z);
if (c!=EOZ)
Proto* f=LoadChunk(L,Z);
if (zgetc(Z)!=EOZ)
luaO_verror(L,l_s("`%.99s' apparently contains more than one chunk"),ZNAME(Z));
return f;
}
Expand Down
5 changes: 2 additions & 3 deletions lundump.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: lundump.h,v 1.23 2001/06/28 13:55:17 lhf Exp $
** $Id: lundump.h,v 1.23 2001/06/28 13:55:17 lhf Exp lhf $
** load pre-compiled Lua chunks
** See Copyright Notice in lua.h
*/
Expand All @@ -19,8 +19,7 @@ int luaU_endianness (void);
/* definitions for headers of binary files */
#define VERSION 0x41 /* last format change was in 4.1 */
#define VERSION0 0x41 /* last major change was in 4.1 */
#define ID_CHUNK 27 /* binary files start with ESC... */
#define SIGNATURE "Lua" /* ...followed by this signature */
#define LUA_SIGNATURE "\033Lua" /* binary files start with <esc>Lua */

/* a multiple of PI for testing native format */
/* multiplying by 1E8 gives non-trivial integer values */
Expand Down

0 comments on commit 9f25df0

Please sign in to comment.