mirror of
https://github.com/lua/lua
synced 2025-03-25 07:02:51 +03:00
new definition for headers of binary files
This commit is contained in:
parent
ae1cf64348
commit
9f25df02d5
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
|
||||
** 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 */
|
||||
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 */
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
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);
|
||||
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)
|
||||
@ -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));
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user