new definition for headers of binary files
This commit is contained in:
6
ldo.c
6
ldo.c
@@ -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
|
** Stack and Call structure of Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -243,7 +243,7 @@ LUA_API int lua_loadfile (lua_State *L, const l_char *filename) {
|
|||||||
int nlevel; /* level on the stack of filename */
|
int nlevel; /* level on the stack of filename */
|
||||||
FILE *f = (filename == NULL) ? stdin : fopen(filename, l_s("r"));
|
FILE *f = (filename == NULL) ? stdin : fopen(filename, l_s("r"));
|
||||||
if (f == NULL) return LUA_ERRFILE; /* unable to open file */
|
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) {
|
if (bin && f != stdin) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
f = fopen(filename, l_s("rb")); /* reopen in binary mode */
|
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,
|
|||||||
int status;
|
int status;
|
||||||
if (!name) name = l_s("?");
|
if (!name) name = l_s("?");
|
||||||
luaZ_mopen(&z, buff, size, name);
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
lundump.c
14
lundump.c
@@ -165,8 +165,7 @@ static void LoadConstants (lua_State* L, Proto* f, ZIO* Z, int swap)
|
|||||||
n=LoadInt(L,Z,swap);
|
n=LoadInt(L,Z,swap);
|
||||||
f->p=luaM_newvector(L,n,Proto*);
|
f->p=luaM_newvector(L,n,Proto*);
|
||||||
f->sizep=n;
|
f->sizep=n;
|
||||||
for (i=0; i<n; i++)
|
for (i=0; i<n; i++) f->p[i]=LoadFunction(L,Z,swap);
|
||||||
f->p[i]=LoadFunction(L,Z,swap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap)
|
static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap)
|
||||||
@@ -190,7 +189,7 @@ static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap)
|
|||||||
|
|
||||||
static void LoadSignature (lua_State* L, ZIO* Z)
|
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)
|
while (*s!=0 && ezgetc(L,Z)==*s)
|
||||||
++s;
|
++s;
|
||||||
if (*s!=0) luaO_verror(L,l_s("bad signature in `%.99s'"),ZNAME(Z));
|
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)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
** load one chunk from a file or buffer
|
** 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* luaU_undump (lua_State* L, ZIO* Z)
|
||||||
{
|
{
|
||||||
Proto* f=NULL;
|
Proto* f=LoadChunk(L,Z);
|
||||||
int c=zgetc(Z);
|
if (zgetc(Z)!=EOZ)
|
||||||
if (c==ID_CHUNK)
|
|
||||||
f=LoadChunk(L,Z);
|
|
||||||
c=zgetc(Z);
|
|
||||||
if (c!=EOZ)
|
|
||||||
luaO_verror(L,l_s("`%.99s' apparently contains more than one chunk"),ZNAME(Z));
|
luaO_verror(L,l_s("`%.99s' apparently contains more than one chunk"),ZNAME(Z));
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
** load pre-compiled Lua chunks
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -19,8 +19,7 @@ int luaU_endianness (void);
|
|||||||
/* definitions for headers of binary files */
|
/* definitions for headers of binary files */
|
||||||
#define VERSION 0x41 /* last format change was in 4.1 */
|
#define VERSION 0x41 /* last format change was in 4.1 */
|
||||||
#define VERSION0 0x41 /* last major 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 LUA_SIGNATURE "\033Lua" /* binary files start with <esc>Lua */
|
||||||
#define SIGNATURE "Lua" /* ...followed by this signature */
|
|
||||||
|
|
||||||
/* a multiple of PI for testing native format */
|
/* a multiple of PI for testing native format */
|
||||||
/* multiplying by 1E8 gives non-trivial integer values */
|
/* multiplying by 1E8 gives non-trivial integer values */
|
||||||
|
|||||||
Reference in New Issue
Block a user